本帖最后由 透过生活 于 2014-2-16 18:47 编辑
对于多态的理解,有点不太懂。我想知道这个小程序的执行顺序。求详解
abstract class Student{
public abstract void study();
public void sleep(){
System.out.println("天天睡觉");
}
}
class DoStudent{
public void do(Student s){
s.study();
s.sleep();
}
}
class BaseStudent extends Student{
public void study(){
System.out.println("bese study");
}
}
class AdvStudent extends Student{
public void study(){
System.out.println("adv study");
}
public void sleep(){
System.out.println("夜夜睡觉");
}
}
public class Test{
public static void main(String args []){
DoStudent ds = new DoStudent();
ds.do(new BaseStudent());
ds.do(new AdvStudent());
}
}
|
|