public class TestChouXi {
public static void main(String[] args){
Fruit fruit = new Apple(); //访问了父类的无参构造
fruit.sleep();
fruit.eat(); //调用父类的抽象方法,子类干活
((Apple) fruit).fly();
// Fruit fruit = new Fruit(); {
// } 抽象类不能实例化,就是不能创建类对象
}
}
abstract class Fruit{
int sum = 10;
String name = "zhu";
Fruit(){
System.out.println("我是父类无参构造=======");
}
void sleep(){
System.out.println("我想睡觉了==========");
}
abstract void eat();
}
class Apple extends Fruit{
@Override //重写方法的注解
void eat() {
System.out.println("我要吃饭=====");
}
void fly(){
System.out.println("我想要飞====");
}
05-13