英文:
How to do get needed return vaule from multiple inheritence in java?
问题
我正在做Java谜题,以加深我对Java的理解,但有两个问题真的让我感到困惑:
在这种情况下,我怎么样才能从B类中获得所需的返回值?谢谢。
英文:
I am doing java puzzles to enhance my understanding about java but there two questions really confused me:
How can I get the needed return value from class B in that case? Thx.
答案1
得分: 0
什么是所需值的含义?据我理解,您指的是更改超类的值。
希望这段代码能帮助您。
class A0 {
int f;
A0(int f) {
this.f = f;
}
}
class A1 extends A0 {
int f = 0;
A1(int f) {
super(f);
this.f = f;
}
}
class B extends A1 {
int f = 0;
B(int f) {
super(f);
System.out.println(super.f);
this.f = f;
}
int getFofA() {
return f;
}
}
public class question {
public static void main(String[] arg) {
B b0 = new B(5);
System.out.println(b0.getFofA());
}
}
英文:
What do you meaning by needed value? As I understand it, you mean changing the value of the super class.
I hope this code will help you.
class A0 {
int f;
A0(int f) {
this.f = f;
}
}
class A1 extends A0 {
int f = 0;
A1(int f) {
super(f);
this.f=f;
}
}
class B extends A1 {
int f = 0;
B(int f) {
super(f);
System.out.println(super.f);
this.f=f;
}
int getFofA() {
return f;
}
}
public class question {
public static void main(String[] arg) {
B b0 = new B(5);
System.out.println(b0.getFofA());
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论