假设有三个类A
,B
和C
:
public class A {
int op1; // op for operand
int op2;
int op3;
public A(int op1, int op2, int op3) {
this.op1 = op1;
this.op2 = op2;
this.op3 = op3;
}
public A(A a) {
// Is this valid?
this = a;
}
}
public class B extends A {
public B(int op1, int op2, int op3) {
super(op1,op2,op3);
}
}
public class C extends A {
private ArrayList<Integer> array;
public C(B b) {
// Can the base class be initialized without
// calling the constructor that initializes each
// attribute individually?
super(b);
array = new ArrayList<Integer>();
}
}
是否可以使用在C类构造函数中作为参数接收的对象来调用基础构造函数?