程序填空题:sdut-oop-1-测试对象初始化(构造方法)
阅读程序,补全以下程序:
```
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!
```
答案:
第1空:this();
第2空:this(0);
```
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!
```
答案:
第1空:this();
第2空:this(0);