1. public class Test {  2. int x= 12;  3. public void method

题目
单选题
1. public class Test {  2. int x= 12;  3. public void method(int x) {  4. x+=x;  5. System.out.println(x);  6. }  7. }  Given:  34. Test t = new Test();  35. t.method(5);  What is the output from line 5 of the Test class?()
A

 5

B

 10

C

 12

D

 17

E

 24

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

public class Test{2.int x=12;3.public void method(intx){4.x+=x;5.System.out.println(x);6.}7.}Given:34.Test t=new Test();35.t.method(5);What is the output from line 5 of the Test class?()

A.5

B.10

C.12

D.17

E.24


参考答案:B

第2题:

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

第3题:

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

第4题:

给定java代码如下所示,在A处新增下列()方法,是对cal方法的重载。public class Test {  public void cal(int x, int y, int z) { } //A } 

  • A、public int cal(int x,int y,float z){return 0;}
  • B、public int cal(int x,int y,int z){return 0;}
  • C、public void cal(int x,int z){}
  • D、public viod cal(int z,int y,int x){}

正确答案:A,C

第5题:

以下代码的输出结果?public class Test{int x=3;public static void main(String argv[]){int x= 012;System.out.println(x);}}

A.12

B.012

C.10

D.3


正确答案:C

第6题:

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

第7题:

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

第8题:

下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te

A.0

B.1

C.2

D.3


正确答案:C

第9题:

以下程序调试结果为:

public class Test {

int m=5;

public void some(int x) {

m=x;

}

public static void main(String args []) {

new Demo().some(7);

}

}

class Demo extends Test {

int m=8;

public void some(int x) {

super.some(x);

System.out.println(m);

}

}

A.5

B.8

C.7

D.无任何输出

E.编译错误


正确答案:B

第10题:

1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()

  • A、 Line 33 must be called within a try block.
  • B、 The exception thrown by method1 in class a is not required to be caught.
  • C、 The method declared on line 31 must be declared to throw a RuntimeException.
  • D、 On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.

正确答案:B

更多相关问题