单选题:分析如下代码,正确的是( )。
分析如下代码,正确的是( )。 @[B](2)
```
class TempClass {
int i;
public void TempClass(int j) {
int i = j;
}
}
public class C {
public static void main(String[] args) {
TempClass temp = new TempClass(2);
}
}
```
A. 程序编译错误,因为TempClass没有缺省构造函数。
B. 程序编译错误,因为TempClass没有带一个int参数的构造函数。
C. 程序编译正确,但无法运行因为类C不是公共类。
D. 程序编译和运行都正确。
A.程序编译错误,因为TempClass没有缺省构造函数。
B.程序编译错误,因为TempClass没有带一个int参数的构造函数。
C.程序编译正确,但无法运行因为类C不是公共类。
D.程序编译和运行都正确。
答案:B
```
class TempClass {
int i;
public void TempClass(int j) {
int i = j;
}
}
public class C {
public static void main(String[] args) {
TempClass temp = new TempClass(2);
}
}
```
A. 程序编译错误,因为TempClass没有缺省构造函数。
B. 程序编译错误,因为TempClass没有带一个int参数的构造函数。
C. 程序编译正确,但无法运行因为类C不是公共类。
D. 程序编译和运行都正确。
A.程序编译错误,因为TempClass没有缺省构造函数。
B.程序编译错误,因为TempClass没有带一个int参数的构造函数。
C.程序编译正确,但无法运行因为类C不是公共类。
D.程序编译和运行都正确。
答案:B