<分区>
如果我将 this(1);
移动到最后一行,我不明白为什么下面的代码显示错误 Constructor call must be the first statement in a constructor
在构造函数中。
package learn.basic.corejava;
public class A {
int x,y;
A()
{
// this(1);// ->> works fine if written here
System.out.println("1");
this(1); //Error: Constructor call must be the first statement in a constructor
}
A(int a)
{
System.out.println("2");
}
public static void main(String[] args) {
A obj1=new A(2);
}
}
我已经在 StackOverflow 上检查了很多关于这个主题的答案,但我仍然无法理解其中的原因。请用一些简单的例子和解释帮助我弄清楚这个错误。