class Super{
public void m(){
System.out.println("m() in Super");
}
}
class Sub extends Super{
public void m(){
System.out.println("m() in Sub");
}
}
public class TestSuperSub{
public static void foo(Super s){
s.m();
}
public static void main(String args[]){
Sub sub = new Sub();
Super sup = new Super();
foo(sup);
foo(sub);
}
}
(多态)代码练习
最新推荐文章于 2024-03-28 22:26:53 发布