我有困惑请帮忙
class Animal {
public void move() {
System.out.println("Animals can move");
}
}
class Dog extends Animal {
public void move() {
System.out.println("Dogs can walk and run");
}
}
public class TestDog {
public static void main(String args[]) {
Animal a = new Animal(); // Animal reference and object
**Animal b = new Dog(); // Animal reference but Dog object**
a.move(); // runs the method in Animal class
b.move(); // runs the method in Dog class
}
}
创建Animal引用但Dog对象我们可以完成
Dog b = new Dog();
我们会得到相同的结果, 所以我只是想知道差异是什么,我们什么时候使用它?