10. public class Hello {  11. String title;  12. int value; 

题目
单选题
10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?()
A

 Hello

B

 Hello World

C

 Compilation fails.

D

 Hello World 5

E

 The code runs with no output.

F

 An exception is thrown at runtime.

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

第1题:

10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?() 

  • A、 StackOverflowError
  • B、 NullPointerException
  • C、 NumberFormatException
  • D、 IllegalArgumentException
  • E、 ExceptionlnlnitializerError

正确答案:A

第2题:

Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()

  • A、 Class a will not compile.
  • B、 Line 46 can throw the unchecked exception TestException.
  • C、 Line 45 can throw the unchecked exception TestException.
  • D、 Line 46 will compile if the enclosing method throws a TestException.
  • E、 Line 46 will compile if enclosed in a try block, where TestException is caught.

正确答案:D,E

第3题:

下面程序创建了一个线程并运行,请填空,使程序完整。

public class ThreadTest {

public static void main (String[] args) {

Hello h=Hew Hello ();

【 】

t.start ();

}

}

class Hello implements Runnable {

int i;

public void run () {

while(true) {

System.out.println("Hello" +i++);

if(i==5) break;

}

}

}


正确答案:Threadt=new Thread(h);
Threadt=new Thread(h); 解析:在通过实现Runnable接口来创建线程以后,该线程的启动将使得对象的run ()方法被调用。题目中缺少线程创建的语句,因此应该填写Thread t=new Thread(h);,该语句创建 Hello类的实例对象h的线程。

第4题:

1. public class test (  2. public static void main(string args[]) {  3. int 1= 0;  4. while (i)  {  5. if (i==4) {  6. break;  7. }  8. ++i;  9. }  10.    11. }  12. )   What is the value of i at line 10?()

  • A、 0
  • B、 3
  • C、 4
  • D、 5
  • E、 The code will not compile.

正确答案:E

第5题:

Assume that country is set for each class.  Given:  10. public class Money {  11. private String country, name;  12. public getCountry() { return country; }  13.}  and:  24. class Yen extends Money {  25. public String getCountry() { return super.country; }  26. }  27.  28. class Euro extends Money {  29. public String getCountry(String timeZone) {  30. return super.getCountry();  31. }  32. }  Which two are correct?()

  • A、 Yen returns correct values.
  • B、 Euro returns correct values.
  • C、 An exception is thrown at runtime.
  • D、 Yen and Euro both return correct values.
  • E、 Compilation fails because of an error at line 25.
  • F、 Compilation fails because of an error at line 30.

正确答案:B,E

第6题:

public class ClassA{ public int getValue(){ int value=0; boolean setting=true; String title="Hello"; if(value||(setting && title=="Hello")){return 1;} if(value==1&title.equals("Hello")){return 2;} } } And: ClassA a=new ClassA(); a.getValue(); What is the result?()

  • A、1
  • B、2
  • C、Compilation fails.
  • D、The code runs with no output.
  • E、An exception is thrown at runtime.

正确答案:C

第7题:

class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  

  • A、 0
  • B、 1
  • C、 2
  • D、 Compilation fails.

正确答案:C

第8题:

package test;class Target{public String name="hello";}What can directly access and change the value of the variable name?()

A.any class

B.only the Target class

C.any class in the test package

D.any class that extends Target


参考答案:C

第9题:

10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?() 

  • A、 Hello
  • B、 Hello World
  • C、 Compilation fails.
  • D、 Hello World 5
  • E、 The code runs with no output.
  • F、 An exception is thrown at runtime.

正确答案:C

第10题:

1. public class A {  2.  3. private int counter = 0;  4.  5. public static int getInstanceCount() {  6. return counter;  7. }  8.  9. public A() {  10. counter++;  11. }  12.  13. }  Given this code from Class B:  25.A a1 =new A();  26. A a2 =new A();  27. A a3 =new A();  28. System.out.printIn(A.getInstanceCount() ); What is the result?() 

  • A、 Compilation of class A fails.
  • B、 Line 28 prints the value 3 to System.out.
  • C、 Line 28 prints the value 1 to System.out.
  • D、 A runtime error occurs when line 25 executes.
  • E、 Compilation fails because of an error on line 28.

正确答案:A

更多相关问题