Java-abstract(抽象)、final、static
2017-08-23 16:23
246 查看
抽象类和抽象方法(abstract)
抽象类不能被实例化,只能被继承抽象类中不一定都是抽象方法
抽象类中的抽象方法必须被非抽象子类实现
抽象方法必须放在抽象类内
抽象方法没有方法体
//抽象类 abstract class Instrument { private String brand; //品牌 private double weight;//重量 public Instrument() { super(); } public Instrument(String brand, double weight) { super(); this.brand = brand; this.weight = weight; } //抽象方法 public abstract void play(); //get、set方法略,下同 } class Piano extends Instrument { protected double size;//尺寸 public Piano() { super(); } public Piano(String brand, double weight, double size) { super(brand, weight); this.size = size; } @Override public void play(){ System.out.println("演奏钢琴"); } } class Violin extends Instrument { protected double length; public Violin() { super(); } public Violin(String brand, double weight, double length) { super(brand, weight); this.length = length; } @Override public void play(){ System.out.println("演奏小提琴"); } }
final
final修饰的类不能被继承;final修饰的方法不能被重写;
final修饰的属性值不能被修改。
static
static可以用来修饰属性、方法和代码块static修饰的属性和方法称为类属性(类变量)、类方法(区别于成员属性、成员方法)
父类和子类中都有static变量,初始化顺序:
1.父类static变量/代码块 初始化
2.子类static变量/代码块 初始化
3.父类构造方法
4.子类构造方法
相关文章推荐
- java中Static&Final的使用方法,&&&Java中两个主要的抽象Abstract&&Implement
- Java修饰符:public、protected、private、abstract、static和final区别
- java学习笔记之static,final,abstract修饰符和接口
- Java final static abstract关键字介绍
- java中abstract,interface,final,static的总结
- java关键字abstract,static,final,this,super
- Java修饰符 abstract,static,final 的区别详解
- Java - 抽象的(abstract)方法是否可同时是静态的(static),是否可同时是本地方法(native),是否可同时被synchronized修饰?
- java中抽象的(abstract)方法是否可同时是静态的(static),是否可同时是本地方法(native),是否可同时被synchronized修饰
- 总结下java中abstract,interface,final,static
- JAVA基础知识(static,final,abstract)浅谈
- Java修饰符 abstract,static,final 的区别详解
- 引用 java中abstract,interface,final,static,加深理解
- 引用 java中abstract,interface,final,static,加深理解
- (转)总结下java中abstract,interface,final,static,加深理解
- Java中的修饰符说明(public,private,protected,default,final,abstract,static)
- Java之static_final_abstract
- Java中abstract、interface、static和final关键字
- Java的abstract,static ,final关键字的用法
- Java基础(八) Java修饰符及接口详解之(一)static/final/abstract关键字及接口的使用