本帖最后由 孟伟娟 于 2012-11-24 21:34 编辑
class Rodent{
public void eat(){
System.out.println("Rodent.eat()");
drink();
}
public void drink(){
System.out.println("Rodent.drink()");
}
}
class Mouse extends Rodent{
public void drink(){
System.out.println("Mouse.drink()");
}
}
public class DuotaiTest {
public static void main(String[] args){
Rodent m = new Mouse();
m.eat();
}
}
其结果是:Rodent.eat()
Mouse.drink()
解释一下该代码是如何运行的,为什么会出现上述结果?
|