分数 5
补全以下程序,使得程序输出结果与下述结果一致。
public class Main { public static void main(String[] args) { Test test = new Test(true); } } class Test { public Test(){ System.out.println("Constructor one invoked!"); } public Test(int x){ //此处添加代码 System.out.println("Constructor two invoked!"); } public Test(boolean b){ //此处添加代码 System.out.println("Constructor three invoked!"); } } ### 输出样例: Constructor one invoked! Constructor two invoked! Constructor three invoked!
public class Main {
public static void main(String[] args) {
Test test = new Test(true);
}
}
class Test {
public Test(){
System.out.println("Constructor one invoked!");
}
public Test(int x){
this();
System.out.println("Constructor two invoked!");
}
public Test(boolean b){
this(1);
System.out.println("Constructor three invoked!");
}
}