new Thread() { public void run() { doStuff(); } }
new Thread() { public void start() { doStuff(); } }
new Thread() { public void start() { doStuff(); } } .run();
new Thread() { public void run() { doStuff(); } } .start();
new Thread(new Runnable() { public void run() { doStuff(); } } ).run();
new Thread(new Runnable() { public void run() { doStuff(); } }).start();
第1题:
下列程序的执行结果是______。 class A5 extends Thread { boolean b; A5 (boolean bb) { b = bb; } public void run() { System.out.println(this.getName() + "运行"); } } public class Testl5 { public static void main(String[] args) { A5 a1 = new A5(true); A5 a2 = new A5(false); if(a1.b) A1.start(); if (a2 .b) A2.start(); } }
A.Thread-0
B.Thread-1
C.Thread-0
D.Thread-1 Thread-1 Thread-0
第2题:
请阅读下面程序,说明该程序创建线程使用的方法是( )。 public class ThreadTest { public static void main(String args[]) { Thread tl=new Thread(new HolloWorld); Thread t2=new Thread(new HolloWorld); tl.start; t2.Start; } } class HolloWorld implements Runnable { int i; public void run { while(true) { System.out.println("HolloWorld"+i++); if(i= =5)break; } } }
A.继承Thread类
B.实现Runnable接口
C.tl.start
D.t2.start
第3题:
class MyThread extends Thread { public void run() { System.out.println(“AAA”); } public void run(Runnable r) { System.out.println(“BBB”); } public static void main(String[] args) { new Thread(new MyThread()).start(); } } What is the result?()
第4题:
public class Threads2 implements Runnable { public void nun() { System.out.println(”run.”); throw new RuntimeException(”Problem”); } public static void main(String[] args) { Thread t = new Thread(new Threads2()); t.start(); System.out.println(”End of method.”); } } Which two can be results?()
第5题:
public class A extends Thread { A() { setDaemon(true); } public void run() { (new B()).start(); try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“A done”); } class B extends Thread { public void run() { try { Thread.sleep(60000); } catch (InterruptedException x) {} System.out.println(“B done”); } } public static void main(String[] args) { (new A()).start(); } } What is the result?()
第6题:
public class TwoThreads { private static Object resource = new Object(); private static void delay(long n) { try { Thread.sleep(n); } catch (Exception e) { System.out.print(”Error “); } } public static void main(String[] args) { System.out.print(”StartMain “); new Thread1().start(); delay(1000); Thread t2 = new Thread2(); t2.start(); delay(1000); t2.interrupt delay(1000); System.out.print(”EndMain “); } static class Thread 1 extends Thread { public void run() { synchronized (resource) { System.out.print(”Startl “); delay(6000); System.out.print(”End1 “); } } } static class Thread2 extends Thread { public void run() { synchronized (resource) { System.out.print(”Start2 “); delay(2000); System.out.print(”End2 “); } } } } Assume that sleep(n) executes in exactly m milliseconds, and all other code executes in an insignificant amount of time. What is the output if the main() method is run?()
第7题:
public class Threads4 { public static void main (String[] args) { new Threads4().go(); } public void go() { Runnable r = new Runnable() { public void run() { System.out.print(”foo”); } }; Thread t = new Thread(r); t.start(); t.start(); } } What is the result?()
第8题:
Which two code fragments will execute the method doStuff() in a separate thread?()
第9题:
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”.
第10题:
java.lang.RuntimeException: Problem
run. java.lang.RuntimeException: Problem
End of method. java.lang.RuntimeException: Problem
End of method. run. java.lang.RuntimeException: Problem
run. java.lang.RuntimeException: Problem End of method.
第11题:
new Thread() { public void run() { doStuff(); } }
new Thread() { public void start() { doStuff(); } }
new Thread() { public void start() { doStuff(); } } .run();
new Thread() { public void run() { doStuff(); } } .start();
new Thread(new Runnable() { public void run() { doStuff(); } } ).run();
new Thread(new Runnable() { public void run() { doStuff(); } }).start();
第12题:
A done
B done
A done B done
B done A done
There is no exception that the application will print anything.
The application outputs “A done” and “B done”, in no guaranteed order.
第13题:
阅读下面程序 public class Test implements Runnable { public static void main(String[] args) { ______ t.start(); } public void run() { System.out.println("Hello!"); } } 程序中下画线处应填入的正确选项是
A.Test t=new Test();
B.Thread t=new Thread();
C.Thread t=new Thread(new Test());
D.Test t=new Thread();
第14题:
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?()
第15题:
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?()
第16题:
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?()
第17题:
Which two code fragments will execute the method doStuff() in a separate thread?()
第18题:
class Work implements Runnable { Thread other; Work(Thread other) { this.other = other; } public void run() { try { other.join(); } catch (Exception e) { } System.out.print("after join "); } } class Launch { public static void main(String [] args) { new Thread(new Work(Thread.currentThread())).start(); System.out.print("after start "); } } 结果为:()
第19题:
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();
第20题:
You are creating a Windows Forms application by using the .NET Framework 3.5. The application requires a thread that accepts a single integer parameter. You write the following code segment (Line numbers are included for reference only.) Thread myThread = new Thread(new ParameterizedThreadStart(DoWork)) ; myThread.Start(100); You need to declare the method signature of the DoWork method. Which method signature should you use?()
第21题:
AAA
BBB
Compilation fails.
The code runs with no output.
第22题:
Compilation fails.
An exception is thrown at runtime.
The code executes normally and prints „foo”.
The code executes normally, but nothing is printed.
第23题:
new Thread() {public void run() { doStuff(); }};
new Thread() {public void start() { doStuff(); }};
new Thread() {public void start() { doStuff(); }}.run();
new Thread() {public void run() { doStuff(); }}.start();
new Thread(new Runnable() {public void run() { doStuff(); }}).start();
第24题:
Code block a.
Code block B.
Code block c.
Code block d.
Code block e.