单项选择题
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.
相关考题
-
单项选择题
What will be written to the standard output when the following program is run?() public class Qd803 { public static void main(String args[]) { String word = "restructure"; System.out.println(word.substring(2, 3)); } }
A.est
B.es
C.str
D.st
E.s -
单项选择题
What is wrong with the following code?() class MyException extends Exception {} public class Qb4ab { public void foo() { try { bar(); } finally { baz(); } catch (MyException e) {} } public void bar() throws MyException { throw new MyException(); } public void baz() throws RuntimeException { throw new RuntimeException(); } }
A.Since the method foo() does not catch the exception generated by the method baz(), it must declare the RuntimeException in its throws clause.
B.A try block cannot be followed by both a catch and a finally block.
C.An empty catch block is not allowed.
D.A catch block cannot follow a finally block.
E.A finally block must always follow one or more catch blocks. -
多项选择题
Whichstatementsaretrueconcerningtheeffectofthe>>and>>>operators?()
A.For non-negative values of the left operand, the >> and >>> operators will have the same effect.
B.The result of (-1 >> 1) is 0.
C.The result of (-1 >>> 1) is -1.
D.The value returned by >>> will never be negative as long as the value of the right operand is equal to or greater than 1.
E.When using the >> operator, the leftmost bit of the bit representation of the resulting value will always be the same bit value as the leftmost bit of the bit representation of the left operand.
