DESKTOP-D9IGLU5_20200910-赵继豪
1、问题
class Animal{
public void move(){
System.out.println("动物可以移动");
}
}
class Dog extends Animal{
public void move(){
System.out.println("狗可以跑和走");
}
public void bark(){
System.out.println("狗可以吠叫");
}
}
public class TestDog{
public static void main(String[] args){
Animal a = new Animal();
Animal b = new Dog();
a.move();
b.move();
b.bark();
}
}
解析:编译错误:编译看左边,运行看右边。父类型引用指向子类型对象,无法调用只在子类型里定义的方法
2、吐槽
这天气变化,昨天凉快,今天热死了
近期评论