【发布时间】:2015-05-13 22:20:22
【问题描述】:
这里给狗对象提供动物引用的目的是什么..我们可以通过为狗类创建对象来直接访问该方法,请澄清
class Animal{
public void move(){
System.out.println("Animals can move");
}
}
class Dog extends Animal{
public void move(){
super.move(); // invokes the super class method
System.out.println("Dogs can walk and run");
}
}
public class TestDog{
public static void main(String args[]){
Animal b = new Dog(); // Animal reference but Dog object
b.move(); //Runs the method in Dog class
}
}
【问题讨论】:
标签: overriding