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!;
这是怎么回事呢?
[解决办法]
继承了父类的方法包括私有的