在如下源代码文件Test.java中, 哪个是正确的类定义?
A、 public class test {
public int x = 0;
public test(int x)
{
this.x = x;
}
}
B、public class Test{
public int x = 0;
public Test(int x) {
this.x = x;
}
}
C、public class Test extends T1, T2 {
public int x = 0;
public Test (int x) {
this.x = x;
}
}
D、 public class Test extends T1{
public int x=0;
public Test(int x){
this.x = x;
}
}
E、protected class Test extends T2{
public int x=0;
public Test(int x){
this.x=x;
}
}
答:
A、 public class test {
public int x = 0;
public test(int x)
{
this.x = x;
}
}
B、public class Test{
public int x = 0;
public Test(int x) {
this.x = x;
}
}
C、public class Test extends T1, T2 {
public int x = 0;
public Test (int x) {
this.x = x;
}
}
D、 public class Test extends T1{
public int x=0;
public Test(int x){
this.x = x;
}
}
E、protected class Test extends T2{
public int x=0;
public Test(int x){
this.x=x;
}
}
答:
D,E 没有说得很清楚,因为没有给出T1,T2的定义。
如果是单选就选B。没错
多选就选B,D,E。
分析:
1> 源代码文件为Test.java。那么公共类肯定是public class Test这样的形式,所以A 是错的。
2> JAVA中是单继承。
C中 public class Test extends T1, T2 明显是错的。
Cjava里类是单继承的 可以继承多个接口但是用impelements关键字
Eprotected类不能继承