面向对象程序设(Gxw-2 Java part).ppt

面向对象程序设(Gxw-2 Java part)

* 方法覆盖和多态性( Polymorphism )示例 class A{ void f(){System.out.println(“A”);} //自动多态 } class B extends A{ void f(){System.out.println(“B”);} //自动多态 } class C extends B{ final void f(){ System.out.println(“C”);} //再也不能被子类覆盖 } class D extends C{ //final void f(){ System.out.println(“D”); } //再不能被覆盖 } public class Polymorphism { public static void main(String[] args) { A o = new A(); o.f(); // A o = new B(); //父类引用直接指向子类对象 o.f(); // B o= new C(); o.f(); // C o = new D(); o.f(); // C } } 习篱粪们捅畔巡碉贰史涉函骨变值霜拌哇栋婉壳美雍盂罚虹储睛庸抨申烈面向对象程序设计(Gxw

文档评论(0)

1亿VIP精品文档

相关文档