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题:
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?()
第2题:
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?()
第3题:
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); } }
第4题:
public class TestOne implements Runnable { public static void main (String[] args) throws Exception { Thread t = new Thread(new TestOne()); t.start(); System.out.print(”Started”); t.join(); System.out.print(”Complete”); } public void run() { for (int i= 0; i< 4; i++) { System.out.print(i); } } } What can be a result?()
第5题:
import java.util.*; public class NameList { private List names = new ArrayList(); public synchronized void add(String name) { names.add(name); } public synchronized void printAll() { for (int i = 0; i
第6题:
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();
第7题:
Compilation fails.
An exception is thrown at runtime.
The code executes and prints “running”.
The code executes and prints “runningrunning”.
The code executes and prints “runningrunningrunning”.
第8题:
The output may be “r1 = 6, r2 = 14”.
The output may be “r1 = 5, r2 = 15”.
The output may be “r1 = 8, r2 = 12”.
The code may run (and complete) with no output.
The code may deadlock (without completing) with no output.
M IllegalStateException or InterruptedException may be thrown at runtime.
第9题:
Compilation fails.
ClassC is displayed.
The code runs with no output.
An exception is thrown at runtime.
第10题:
Compilation fails.
An exception is thrown at runtime.
The code executes and prints “StartedComplete”.
The code executes and prints “StartedComplete0123”.
The code executes and prints “Started0l23Complete”.
第11题:
The code will deadlock.
The code may run with no output.
An exception is thrown at runtime.
The code may run with output “0 6”.
The code may run with output “2 0 6 4‟.
The code may ruin with output “0 2 4 6”.
第12题:
The code will run a backup validation to populate the V$BACKUP_CORRUPTION view and repair corrupt blocks, if any, recorded in the view.
The code will run a backup validate to populate the V$COPY_CORRUPTION view and then repair any corrupt blocks recorded in the view.
The code will runs a backup validate to populate the V$DATABASE_BLOCK_CORRUPTION view and then repair corrupt blocks, if any, recorded in the view.
The code will run a backup validate to populate the RC_BACKUP_CORRUPTION view and then repair corrupt blocks, if any, recorded in the view.
第13题:
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?()
第14题:
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?()
第15题:
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?()
第16题:
public class Foo { public static void main(String[] args) { try { return; } finally { System.out.println( “Finally” ); } } } What is the result?()
第17题:
class Computation extends Thread { private int num; private boolean isComplete; private int result; public Computation(int num) { this.num = num; } public synchronized void run() { result = num * 2; isComplete = true; notify(); } public synchronized int getResult() { while (!isComplete) { try { wait(); } catch (InterruptedException e) { } } return result; } public static void main(String[] args) { Computation[] computations = new Computation [4]; for (int i = 0; i < computations.length; i++) { computations[i] = new Computation(i); computations[i] .start(); } for (Computation c : computations) System.out.print(c.getResult() +“ “); } } What is the result?()
第18题:
You executed the following code: BACKUP VALIDATE DATABASE; BLOCKRECOVER CORRUPTION LIST; What will be the result of executing the above code?()
第19题:
Cat
Dog
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第20题:
An exception may be thrown at runtime.
The code may run with no output, without exiting.
The code may rum with output “A B A B C C “, then exit.
The code may ruin with output “A A A B C A B C C “, then exit.
The code may rum with output “A B C A B C A B C “, then exit.
The code may ruin with output “A B C A A B C A B C “, then exit.
第21题:
The code will fail to compile.
0 will be written to the standard output.
1 will be written to the standard output.
2 will be written to the standard output.
3 will be written to the standard output.
第22题:
The code runs with no output.
Compilation fails.
An exception is thrown at runtime.
ClassC is displayed.
第23题:
Hello
Hello Foo
Hello world
Compilation fails.
The code does not run.