The code will deadlock.
The code may run with output "2 0 6 4".
The code may run with no output.
The code may run with output "0 6".
An exception is thrown at runtime.
The code may run with output "0 2 4 6".
第1题:
A.Compilation fails.
B.ClassC is displayed.
C.The code runs with no output.
D.An exception is thrown at runtime.
第2题:
public class Threads3 implements Runnable { public void run() { System.out.print(”running”); } public static void main(String[] args) { Thread t = new Thread(new Threads3()); t.run(); t.run(); t.start(); } } What is the result?()
第3题:
What happens when you try to compile and run the following program?
class Mystery{String s;public static void main(String[] args){
Mystery m=new Mystery();m.go();}void Mystery(){s=”constructor”;}void go(){System.out.println(s);}
}()
A.this code will not compile
B.this code compliles but throws an exception at runtime
C.this code runs and “constructor” in the standard output
D.this code runs and writes “null” in the standard output
第4题:
What will be the result of attempting to compile and run the following code?() public class Q6b0c { public static void main(String args[]) { int i = 4; float f = 4.3; double d = 1.8; int c = 0; if (i == f) c++; if (((int) (f + d)) == ((int) f + (int) d)) c += 2; System.out.println(c); } }
第5题:
public class Transfers { public static void main(String[] args) throws Exception { Record r1 = new Record(); Record r2 = new Record(); doTransfer(r1, r2, 5); doTransfer(r2, r1, 2); doTransfer(r1, r2, 1); // print the result System.out.println(”rl = “ + r1.get() +“, r2=” + r2.get()); } private static void doTransfer( final Record a, final Record b, final int amount) { Thread t = new Thread() { public void run() { new Clerk().transfer(a, b, amount); } }; t.start(); } } class Clerk { public synchronized void transfer(Record a, Record b, int amount){ synchronized (a) { synchronized (b) { a.add(-amount); b.add(amount); } } } } class Record { int num=10; public int get() { return num; } public void add(int n) { num = num + n; } } If Transfers.main() is run, which three are true?()
第6题:
A.4
B.5
C.8
D.9
E.Compilation fails.
F.An exception is thrown at runtime.
G.It is impossible to determine for certain.
第7题:
public class Threads5 { public static void main (String[] args) { new Thread(new Runnable() { public void run() { System.out.print(”bar”); } }).start(); } } What is the result?()
第8题:
A.Value is: 8
B.Compilation fails.
C.Value is: 12
D.Value is: -12
E.The code runs with no output.
F.An exception is thrown at runtime.
第9题:
public class Foo { public void main( String[] args ) { System.out.println( “Hello” + args[0] ); } } What is the result if this code is executed with the command line?()
第10题:
Runnable r = new Runnable() { public void run() { System.out.print(”Cat”); } }; Threadt=new Thread(r) { public void run() { System.out.print(”Dog”); } }; t.start(); What is the result?()