package study;
abstract class Person{
public static final String FLAG="天河学院";
//sataic表示这个变量是这个类的全体对象所共享的
//final表示这个变量的值不会在发生改变
private int age;
public Person() {
System.out.println("父类的无参构造方法");
}
public abstract String getContent();
}
class Child extends Person{
private String School;
public Child() {
System.out.println("子类的无参数构造方法");
}
public String getContent() {
return FLAG;
}
}
//此处省略了对私有属性的set和get的方法
public class exercise {
public static void main(String[] args) {
Child c=new Child();
System.out.println(c.getContent());
}
}
//抽象类定义了方法而不实现,正因为这样,其子类可以有更多的展现空间和实现能力;
//就好比定义方法名称和返回值,至于如何实现完全交给子类处理
10.1抽象方法的作用
最新推荐文章于 2024-02-03 17:04:05 发布