关于继承和方法覆盖,我有以下练习,问题是为什么调用父类中'initialize()'方法中的'System.out.println(f1)'与参数'0',并且需要做什么将被称为参数'6'。请帮我理解它。提前致谢。Java继承和方法重写程序
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);
}
}
}
' initialize'没有*任何参数...并且你不会在'B'中重写它,因为它是一个私有方法。目前还不清楚你的期望以及为什么,说实话 - 但是你有两个同名的领域只会增加混乱。 –