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.
相关问题推荐
-
public class Foo implements Runnable ( public void run (Thread t) { system.out.printIn(“Running.”); } public static void main (String args) { new thread (new Foo()).start(); } ) What is the result?()
A、 An exception is thrown.
B、 The program exists without printing anything.
C、 An error at line 1 causes compilation to fail.
D、 An error at line 6 causes the compilation to fail.
E、 “Running” is printed and the program exits.
-
What produces a compiler error?()
A、 class A { public A(int x) {} }
B、 class A {} class B extends A { B() {} }
C、 class A { A() {} } class B { public B() {} }
D、 class Z { public Z(int) {} } class A extends Z {}
-
public class ItemTest { private final mt id; public ItemTest(int id) { this.id = id; } public void updateId(int newId) { id = newId; } public static void main(String[] args) { ItemTest fa = new ItemTest(42); fa.updateId(69); System.out.println(fa.id); } } What is the result?()
A、 Compilation fails.
B、 An exception is thrown at runtime.
C、 The attribute id in the Item object remains unchanged.
D、 The attribute id in the Item object is modified to the new value.
E、 A new Item object is created with the preferred value in the id attribute.
-
What is the result?()
A、 12,4
B、 The code runs with no output.
C、 An exception is thrown at runtime.
D、 Compilation fails because of an error in line 21.
E、 Compilation fails because of an error in line 22.
F、 Compilation fails because of an error in line 31.
-
What is the result?()
A、 A,B,C
B、 B,C,A
C、 Compilation fails.
D、 The code runs with no output
E、 An exception is thrown at runtime.