读书人

this 与 方法重写 的烦恼!

发布时间: 2012-01-05 22:36:54 作者: rapoo

this 与 方法重写 的烦恼!!!求助!!

Java code
class Father{     private void hello(){           System.out.println("hello father!");     }     public void f1(){           this.hello();     }}class Son extends Father{     public void hello(){           System.out.println("hello son!");     }}public class Test{     public static void main(String[] args){         student1.f1();     }}


结果会输出:hello father!;
这是怎么回事呢?

[解决办法]
继承了父类的方法包括私有的

读书人网 >J2SE开发

热点推荐