public class Person {
private void print(){
System.out.println("父类");
}
public void printTwo(){
System.out.println("父类");
}
public void fun(){
this.print();
}
public void funTwo(){
this.printTwo();
}
}
public class Student extends Person {
public void print(){
System.out.println("学生");
}
public void printTwo(){
System.out.println("学生");
}
}
public class TestStudent {
public static void main(String[] args) {
Student student =new Student();
student.fun();
student.print();
student.funTwo();
student.printTwo();
}
}
结果:
父类
学生
学生
学生
请教下这两种结果为什么会不同
------解决方案--------------------
private 的方法能不能被子类重写
Person中的print方法是private的