面向对象高级程序设计.pptVIP

  • 4
  • 0
  • 约1.53万字
  • 约 51页
  • 2019-10-16 发布于湖北
  • 举报
5.2多态性 【例5-7】方法重写的例子 class Parent{ public void function(){ System.out.println(I am in Parent!); } } class Child extends Parent{ private void function(){ System.out.println(I am in Child!); } } public class RTpolyTest{ public static void main(String args[]){ Parent pl=new Parent( ); Parent p2=new Child( ); p1.function( ); p2.function( ); } } 5.2多态性 编译过程如下: D:\user\chap05Javac RTpolyTest.java RTpolyTest.java:8: function() in Child cannot override function() in Parent; attempting to assign weaker access privileges; was public

文档评论(0)

1亿VIP精品文档

相关文档