重写 与权限的问题

名剑_无名 2014-08-28 03:01:28
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();
}
}
结果:
父类
学生
学生
学生
请教下这两种结果为什么会不同
...全文
85 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
名剑_无名 2014-08-28
  • 打赏
  • 举报
回复
引用 1 楼 shixitong 的回复:
private 的方法能不能被子类重写 Person中的print方法是private的
原来如此- -
shixitong 2014-08-28
  • 打赏
  • 举报
回复
private 的方法能不能被子类重写 Person中的print方法是private的

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧