package zh.codegym.task.task15.task1526;
/*
调试、调试和再调试
*/
public class Solution {
public static void main(String[] args) {
new B(6);
}
public static class A {
private int f1 = 7;
public A(int f1) {
this.f1 = f1;
initialize();
}
protected void initialize() {
System.out.println(f1);
}
}
public static class B extends A {
protected int f1 = 3;
public B(int f1) {
super(f1);
this.f1 += f1;
initialize();
}
protected void initialize() {
System.out.println(f1);
}
}
}
为什么class A中的initialize()方法为protected的时候,在执行public A(int f1) 里的 initialize()方法时,它调用的是class B里面的 initialize()方法。而把classA里面的 initialize()改为private时,它执行的就是class A 里面的 initialize()方法。有人能为我解答一下么
已解决
评论 (5)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
Gellert Varga
16 九月 2021, 19:18
At this link:
https://codegym.cc/tasks/com.codegym.task.task15.task1526
Guadalupe explains this exercise very well in this post: 8 April 2020, 17:28
If you need, use this free translator: deepl.com
0
leeway
16 九月 2021, 21:36
你好,感谢你的回复!
但是我找不到Guadalupe的回复,能告诉我具体怎么找到这条回复么?谢谢
0
Lisa
16 九月 2021, 22:04解决方法
As a little nerd, I take notes on tasks every now and then. This is another one of those times. Maybe it helps you.
+3
leeway
17 九月 2021, 10:44
非常详细,我理解这道题了。太感谢了!!!thx
0
leeway
17 九月 2021, 10:46
这道题考察的是代码的执行顺序,还有就是父类的私有成员不会被子类继承。搞懂这两点这道题就迎刃而解了
0