CMS专题

单选题interface foo {   int k = 0;   }    public class test implements Foo (   public static void main(String args) (    int i;   Test test = new test ();   i= test.k;   i= Test.k;   i= Foo.k;   )   )   What is the result? ()ACompilation succeeds.BAn error a

题目
单选题
interface foo {   int k = 0;   }    public class test implements Foo (   public static void main(String args) (    int i;   Test test = new test ();   i= test.k;   i= Test.k;   i= Foo.k;   )   )   What is the result? ()
A

 Compilation succeeds.

B

 An error at line 2 causes compilation to fail.

C

 An error at line 9 causes compilation to fail.

D

 An error at line 10 causes compilation to fail.

E

 An error at line 11 causes compilation to fail.

参考答案和解析
正确答案: D
解析: 暂无解析
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Given:Which code, inserted at line 15, allows the class Sprite to compile?()

A.Foo { public int bar() { return 1; }

B.new Foo { public int bar() { return 1; }

C.new Foo() { public int bar() { return 1; }

D.new class Foo { public int bar() { return 1; }


参考答案:C

第2题:

在下列源代码文件Test.java中,正确定义类的代码是( )。

A.pblic 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.protected class Test extends T2{ public int x = 0; public Test(int x) { this. x = x; } }


正确答案:B
解析:本题主要考查类声明格式为[修饰符]class类名[extends父类名][implements类实现的接口列表],选项A中源文件名与程序名不相同,Java不支持多重继承所以选项C错误,选项D中类的访问权限不对,应为public。

第3题:

有如下类定义:

class Foo

{

public:

Foo(int v):value(v){} // ①

~Foo(){} // ②

private:

Foo(){} // ③

int value = 0; // ④

};

其中存在语法错误的行是

A . ①

B . ②

C . ③

D . ④


正确答案:D

第4题:

下列代码中,将引起一个编译错误的行是( )。 1)public class Test{ 2)int m,n; 3)public Test{} 4)public Test(int a){m=a;) 5)public static void main(String args[]){ 6)Test tl,t2; 7)int j,k; 8)j=0;k=0; 9)tl=new Test; 10)t2=new Test(j,k); 11)} 12)}

A.第3行

B.第5行

C.第6行

D.第l0行


正确答案:D
D。【解析】本题考查考生对Java中构造方法的理解及应用。构造方法名必须与类名相同,没有返回值,用户不能直接调用,只能通过new自动调用。题目标两个构造方法Test和Test(inta),按照参数决定调用哪个方法。tl=newTest语句调用Test方法,而t2=newTest(j,k)将会找不到相应的构造方法,程序编译出错在第10行,所以选项D正确。

第5题:

下列代码中,将引起编译错误的行是______。 (1) public class Test { (2) int m,n; (3) public Test( ){} (4) public Test(int A){m=a;} (5) public static void main(String args[ ]){ (6) Test t1,t2; (7) int j,k; (8) j=0;k=0; (9) t1=new Test( ); (10) t2=new Test(j,k); (11) 1 (12) }

A.第3行

B.第5行

C.第6行

D.第10行


正确答案:D
解析: 第10行代码中的参数数目比类Test的任何一个构造方法所声明的形式参数都多,因此引起编译错误。在调用构造函数时,必须严格按照它在类中定义的形式使用,包括参数个数和数据类型等,否则将引起编译错误。

第6题:

下列代码中,将引起一个编译错误的行是( )。 1)public class Test{ 2) int m,n; 3) public Test(){} 4) public Test(int a){m=a;} 5) public static void main(String args[]){ 6) Test t1,t2; 7) int j,k; 8) j=0;k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12)}

A.第3行

B.第5行

C.第6行

D.第10行


正确答案:D
解析:本题考查考生对Java中构造方法的理解及应用。构造方法名必须与类名相同,没有返回值,用户不能直接调用,只能通过new自动调用。题目有两个构造方法Test()和Test(inta),按照参数决定调用哪个方法。t1=newTest()语句调用Test()方法,而t2=newTest(j,k)将会找不到相应的构造方法,程序编译出错在第10行,所以选项D说法正确。

第7题:

有如下类定义: class Foo { public: Foo(int v) : value(v) { } // ① ~Foo() { } // ② private: Foo() { } // ③ int value = 0; // ④ }; 其中存在语法错误的行是( )。

A.①

B.②

C.⑧

D.④


正确答案:D
解析:此题考查的是类的定义。C++语言规定,在类体内不允许对所定义的数据成员进行初始化。

第8题:

在如下源代码文件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


正确答案:BD

第9题:

在下列源代码文件Test.java中, ( )是正确的类定义。

A.public class test{

B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

C.public class Test extends T1,T2{

D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


正确答案:B

第10题:

在下列源代码文件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 Ti,T2 { public int x=0; public Test(int x) { this.x=x; } }

D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }


正确答案:B

更多相关问题