Given that a static method doIt() in a class Work represents

题目
单选题
Given that a static method doIt() in a class Work represents work to be done, what block of code will succeed in starting a new thread that will do the work?   CODE BLOCK a:   Runnable r = new Runnable() {   public void run() {   Work.doIt();   }   };   Thread t = new Thread(r);   t.start();   CODE BLOCK b:   Thread t = new Thread() {  public void start() {   Work.doIt();  }  };   t.start();   CODE BLOCK c:   Runnable r = new Runnable() {   public void run() {   Work.doIt();   }   };   r.start();  CODE BLOCK d:   Thread t = new Thread(new Work());   t.start();   CODE BLOCK e:   Runnable t = new Runnable() {   public void run() {   Work.doIt();   }   };   t.run();
A

Code block a.

B

Code block B.

C

Code block c.

D

Code block d.

E

Code block e.

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

第1题:

下面程序的输出结果是什么? 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

第2题:

Click the Exhibit button. Given:Which statement 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

第3题:

阅读下列代码段,选出该代码段的正确文件名( )。 class A { void methodl() { System.out.println("methodl in class A"); } } public class B { void method2() { System.out.println("method2 in class B"); } public static void main(String args[]) { System.out.println("main in class B"); } }

A.A.java

B.A.class

C.B.class

D.B.java


正确答案:D
解析:Java源程序文件是以.java为后缀的,Java字节码文件以.class为后缀,而且 Java源文件中只能有一个public类,该类的名字为源文件名,程序段中类B是以public修饰的,因此源程序文件名为B.java。

第4题:

Which two statements are true about the hashCode method?()

  • A、 The hashCode method for a given class can be used to test for object equality and object inequality for that class.
  • B、 The hashCode method is used by the java.util.SortedSet collection class to order theelements within that set.
  • C、 The hashCode method for a given class can be used to test for object inequality, but NOT object equality, for that class.
  • D、 The only important characteristic of the values returned by a hashCode method is that the distribution of values must follow a Gaussian distribution.
  • E、 The hashCode method is used by the java.util.HashSet collection class to group the elements within that set into hash buckets for swift retrieval.

正确答案:C,E

第5题:

分析下列代码:  Class A{  Public static void main(String[] args){  method(); }  static void method(){  try{  System.out.println("Hello"); }finally{  System.out.println("good-bye"); } } }  编译运行后,输出结果是()。 

  • A、"Hello"
  • B、"good-bye"
  • C、"Hello""god-bye"
  • D、代码不能编译

正确答案:C

第6题:

GiventhatastaticmethoddoIt()inaclassWorkrepresentsworktobedone,whatblockofcodewillsucceedinstartinganewthreadthatwilldothework?

CODEBLOCKa:

Runnabler=newRunnable(){

publicvoidrun(){

Work.doIt();

}

};

Threadt=newThread(r);

t.start();

CODEBLOCKb:

Threadt=newThread(){

publicvoidstart(){

Work.doIt();}};

t.start();

CODEBLOCKc:

Runnabler=newRunnable(){

publicvoidrun(){

Work.doIt();

}

};

r.start();

CODEBLOCKd:

Threadt=newThread(newWork());

t.start();

CODEBLOCKe:

Runnablet=newRunnable(){

publicvoidrun(){

Work.doIt();

}

};

t.run();


参考答案:A

第7题:

阅读下列代码段,选出该代码段的正确的文件名( )。 class A { void method () { System.out.println ("methodl in class A"); } } public class B { void method2 () { System.out.println("method2 in class B"); } public static void main (String args[]) { System.out.println ("main () in class B"); } }

A.A.java

B.A.class

C.B.class

D.B.java


正确答案:D
解析:Java源文件以.java为后缀,Java字节码文件以.class为后缀。Java源文件中只有一个public的类,该类的名字为源文件名,这里类B是以public修饰的,因此源文件名为B.java。

第8题:

阅读下列代码段,选出该代码段的正确文件名( )。 class A { void method1() { System.out.println("method1 in class A"); } } public class B { void method2() { System.out.println("method2 in class B"); } public static void main(String args[]) { System.out.println("main in class B"); } }

A.A.java

B.A.class

C.B.class

D.B.java


正确答案:D
解析:Java源程序文件是以Java为后缀的,Java字节码文件以.class为后缀,而且 Java源文件中只能有一个public类,该类的名字为源文件名,程序段中类B是以public修饰的,因此源程序文件名为Biava。

第9题:

class A {  protected int method1(int a, int b) { return 0; }  }  Which two are valid in a class that extends class A?() 

  • A、 public int method1(int a, int b) { return 0; }
  • B、 private int method1(int a, int b) { return 0; }
  • C、 private int method1(int a, long b) { return 0; }
  • D、 public short method1(int a, int b) { return 0: }
  • E、 static protected int method1(int a, int b) { return 0; }

正确答案:A,C

第10题:

Given a class Repetition: 1.package utils; 2. 3.public class Repetition{ 4.public static String twice(Strings){returns+s;} 5.} and given another class Demo: 1.//insert code here2. 3.public class Demo{ 4.public static void main(String[]args){ 5.System.out.println(twice("pizza")); 6.} 7.} Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()

  • A、import utils.*;
  • B、static import utils.*;
  • C、importutils.Repetition.*;
  • D、static importutils.Repetition.*;
  • E、import utils.Repetition.twice();
  • F、import static utils.Repetition.twice;
  • G、static import utils.Repetition.twice;

正确答案:F

更多相关问题