标题几乎说明了我的问题。为什么这不可能?我只是想知道架构推理可能是什么。
public class A{
public int x = 5;
public void m1() {System.out.println("Am1--> " + x);}
public void m2() {System.out.println("Am2--> " + this.x);}
public void update() {x = 99;}
}
public class B extends A{
x = 10;
public void m2() {System.out.println("Bm2--> " + x);}
public void m3() {System.out.println("Bm3--> " + super.x);}
// public void m4() {System.out.println("Bm4--> " + super.m2());}
}
答案 0 :(得分:0)
在构造函数或任何其他方法中为 x 指定值:
public class A{
public int x = 5;
public void m1() {System.out.println("Am1--> " + x);}
public void m2() {System.out.println("Am2--> " + this.x);}
public void update() {x = 99;}
}
public class B extends A{
public B(){
super();
x = 10;
}
public void m2() {System.out.println("Bm2--> " + x);}
public void m3() {System.out.println("Bm3--> " + super.x);}
// public void m4() {System.out.println("Bm4--> " + super.m2());}
}