Java 初始化扩展类的基类

Java 初始化扩展类的基类,java,Java,假设有三个类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 cl

假设有三个类
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>();
 }
}
公共A类{
int op1;//操作数的运算
int op2;
int op3;
公共A(int op1、int op2、int op3){
这是op1=op1;
this.op2=op2;
这是op3=op3;
}
公共A(A){
//这有效吗?
这=a;
}
}
公共类B扩展了A{
公共B(int op1、int op2、int op3){
super(op1、op2、op3);
}
}
公共类C扩展了{
私有数组列表数组;
公共图书馆C(B){
//基类是否可以在没有
//调用初始化每个
//单独属性?
超级(b);
数组=新的ArrayList();
}
}

是否可以使用C类构造函数中作为参数接收的对象调用基构造函数?

否不可能。这是一个非常简单的语法问题,您可以通过尝试来回答。因此,在调用基类时,是否不可能使用扩展类初始化其值(因为B是a)?查看“复制构造函数”的外观(您正在尝试创建一个)。@SunilChakravarthy“第二件事,当我们用参数创建构造函数时,我们必须自己不创建参数构造函数。如果不需要,程序将不会运行。“什么?如果需要,只创建一个非参数化构造函数。@SunilChakravarthy最好只创建所需的构造函数,所以如果不需要非参数化构造函数,就不要创建。这只允许在您不喜欢的状态下创建实例。