5. class Order2 implements Runnable { 6. public void run() { 7. for(int x = 0; x 〈 4; x++) { 8. try { Thread.sleep(100); } catch (Exception e) { } 9. System.out.print("r"); 10. } } 11. public static void main(String [] args) { 12. Thread t = new Thread(new Order2()); 13. t.start(); 14. for(int x = 0; x 〈 4; x++) { 15. // insert code here 16. System.out.print("m"); 17. } } } 哪一个插入到第15行,最有可能产生输出 rmrmrmrm ?() A、Thread.sleep(1);B、Thread.sleep(100);C、Thread.sleep(1000);D、try { Thread.sleep(100); } catch (Exception e) { }
5. class Order2 implements Runnable { 6. public void run() { 7. for(int x = 0; x 〈 4; x++) { 8. try { Thread.sleep(100); } catch (Exception e) { } 9. System.out.print("r"); 10. } } 11. public static void main(String [] args) { 12. Thread t = new Thread(new Order2()); 13. t.start(); 14. for(int x = 0; x 〈 4; x++) { 15. // insert code here 16. System.out.print("m"); 17. } } } 哪一个插入到第15行,最有可能产生输出 rmrmrmrm ?()
- A、Thread.sleep(1);
- B、Thread.sleep(100);
- C、Thread.sleep(1000);
- D、try { Thread.sleep(100); } catch (Exception e) { }
相关考题:
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?() A、 Compilation fails.B、 An exception is thrown at runtime.C、 The code executes and prints “running”.D、 The code executes and prints “runningrunning”.E、 The code executes and prints “runningrunningrunning”.
现有: class ThreadExcept implements Runnable { public void run() { throw new RuntimeException("exception "); } public static void main(Stri_ng [] args) { new Thread (new ThreadExcept()).start(); try { int x=Integer.parselnt (args [0]); Thread. sleep (x); System.out.print("main"); } catch (Exception e) { } } } 和命令行: java ThreadExcept l000 哪一个是结果?() A、mainB、编译失败C、main java.lang.RuntimeException: exceptionD、代码运行,但没有输出
1. class A implements Runnable ( 2. int i; 3. public void run ( ) ( 4. try ( 5. thread.sleep(5000); 6. i= 10; 7. ) catch(InterruptedException e) {} 8. ) 9. ) 10. 11. public class Test { 12. public static void main (string args[]) ( 13. try ( 14. A a = new A ( ); 15. Thread t = new Thread (a); 16. t.start( ); 17. 18. int j= a.i; 19. 20. ) catch (Exception e) {} 21. ) 22. } Which statement al line 17 will ensure that j=10 at line 19?() A、 a.wait();B、 t.wait();C、 t.join();D、 t.yield();E、 t.notify();F、 a.notify();G、 t.interrupt();
1. public class X { 2. public static void main (String[]args) { 3. int [] a = new int [1] 4. modify(a); 5. System.out.printIn(a[0]); 6. } 7. 8. public static void modify (int[] a) { 9. a[0] ++; 10. } 11. } What is the result?()A、 The program runs and prints “0”B、 The program runs and prints “1”C、 The program runs but aborts with an exception.D、 An error “possible undefined variable” at line 4 causes compilation to fail.E、 An error “possible undefined variable” at line 9 causes compilation to fail.
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?() A、 A doneB、 B doneC、 A done B doneD、 B done A doneE、 There is no exception that the application will print anything.F、 The application outputs “A done” and “B done”, in no guaranteed order.
class ThreadExcept implements Runnable { public void run() { throw new RuntimeException("exception "); } public static void main(String [] args) { new Thread(new ThreadExcept()).start(); try { int x = Integer.parseInt(args[0]); Thread.sleep(x); System.out.print("main "); } catch (Exception e) { } } } 和命令行: java ThreadExcept 1000 哪一个是结果?() A、 mainB、 编译失败C、 代码运行,但没有输出D、 main java.lang.RuntimeException:exception
1. public class Test { 2. public static String output =””; 3. 4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20. 21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24. 25. }26. } What is the value of the variable output at line 23?()
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?()A、 Compilation fails.B、 An exception is thrown at runtime.C、 The code executes and prints “StartedComplete”.D、 The code executes and prints “StartedComplete0123”.E、 The code executes and prints “Started0l23Complete”.
1. class MyThread implements Runnable { 2. public void run() { 3. System.out.print("go "); 4. } 5. 6. public static void main(String [] args) { 7. // insert code here 8. t.start(); 9. } 10. } 和如下四句: Thread t = new MyThread(); MyThread t = new MyThread(); Thread t = new Thread(new Thread()); Thread t = new Thread(new MyThread()); 分别插入到第5行,有几个可以通过编译?() A、0B、1C、2D、3
class Waiting implements Runnable { boolean flag = false; public synchronized void run() { if (flag) { flag = false; System.out.print("1 "); try { this.wait(); } catch (Exception e) { } System.out.print("2 "); } else { flag = true; System.out.print("3 "); try { Thread.sleep(2000); } catch (Exception e) { } System.out.print("4 "); notify(); } } public static void main(String [] args) { Waiting w = new Waiting(); new Thread(w).start(); new Thread(w).start (); } } 以下哪两项是正确的?() A、代码输出 1 3 4B、代码输出 3 4 1C、代码输出 1 2 3 4D、代码不会完成
现有: 5. class Order2 implements Runnable { 6. public void run() { 7. for (int x- o; x4; x++) { 8. try{Thread.sleep(100); )catch (Exception e) { } 9. System.out.print("r"); 10. } } 11. public static void main(string [] args) { 12. Thread t=new Thread(new order2()); 13. t.start(); 14. for(int x=0; x4; x++) { 15. //insert code here 16. System.out.print("m"); 17. } } } 哪一个插入到第15行,最有可能产生输出 rmrmrmrm?() A、 Thread.sleep(1);B、 Thread.sleep(100);C、 Thread.sleep(1000);D、 try{ Thread.sleep(1); ) catch (Exception e) { }E、 try{Thread.sleep(100); ) catch (Exception e) { }F、 try{Thread.sleep(1000); ) catch (Exception e) { }
2. public class Foo implements Runnable ( 3. public void run (Thread t) { 4. system.out.printIn(“Running.”); 5. } 6. public static void main (String[] args) { 7. new thread (new Foo()).start(); 8. ) 9. ) 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.
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 "); } } 结果为:()A、after joinB、after startC、after join after startD、after start after join
1. class A implements runable ( 2. int i; 3. public void run () ( 4. try ( 5. thread.sleep(5000); 6. i= 10; 7. ) catch(InterruptedException e) {} 8. ) 9. ) 10. 11. public class Test { 12. public static void main (string args) ( 13. try ( 14. A a = new A (); 15. Thread t = new Thread (a); 16. t.start(); 17. 18. int j= a.i; 19. 20. ) catch (Exception e) {} 21. ) 22. ) Which statement al line 17 will ensure that j=10 at line 19?()A、 a.wait();B、 t.wait();C、 t.join();D、 t.yield();E、 t.notify();F、 a.notify();G、 t.interrupt();
class Order implements Runnable { public void run () { try { Thread.sleep (2000) ; } catch (Exception e) System.out.print("in") ; public static void main (String [] args) { Thread t = new Thread (new Order ()) ; t.start () ; System.out.print ("pre ") ; try { t.join () ; } catch (Exception e) { } System.out.print ("post") ; 可产生哪两项结果?() A、 pre in postB、 pre inC、 in post preD、 in pre postE、 pre post in
1. class Exc0 extends Exception { } 2. class Exc1 extends Exc0 { } 3. public class Test { 4. public static void main(String args[]) { 5. try { 6. throw new Exc1(); 7. } catch (Exc0 e0) { 8. System.out.println(“Ex0 caught”); 9. } catch (Exception e) { 10. System.out.println(“exception caught”); 11. } 12. } 13. } What is the result?() A、 Ex0 caughtB、 exception caughtC、 Compilation fails because of an error at line 2.D、 Compilation fails because of an error at line 6.
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?() A、 Compilation fails.B、 An exception is thrown at runtime.C、 The code executes normally and prints „foo”.D、 The code executes normally, but nothing is printed.
单选题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?()A Compilation fails.B An exception is thrown at runtime.C The code executes and prints “running”.D The code executes and prints “runningrunning”.E The code executes and prints “runningrunningrunning”.
多选题class Waiting implements Runnable { boolean flag = false; public synchronized void run() { if (flag) { flag = false; System.out.print("1 "); try { this.wait(); } catch (Exception e) { } System.out.print("2 "); } else { flag = true; System.out.print("3 "); try { Thread.sleep(2000); } catch (Exception e) { } System.out.print("4 "); notify(); } } public static void main(String [] args) { Waiting w = new Waiting(); new Thread(w).start(); new Thread(w).start (); } } 以下哪两项是正确的?()A代码输出 1 3 4B代码输出 3 4 1C代码输出 1 2 3 4D代码不会完成
单选题现有: class ThreadExcept implements Runnable { public void run() { throw new RuntimeException("exception "); } public static void main(Stri_ng [] args) { new Thread (new ThreadExcept()).start(); try { int x=Integer.parselnt (args [0]); Thread. sleep (x); System.out.print("main"); } catch (Exception e) { } } } 和命令行: java ThreadExcept l000 哪一个是结果?()AmainB编译失败Cmain java.lang.RuntimeException: exceptionD代码运行,但没有输出
单选题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?()A Compilation fails.B An exception is thrown at runtime.C The code executes and prints “StartedComplete”.D The code executes and prints “StartedComplete0123”.E The code executes and prints “Started0l23Complete”.
单选题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?()A Compilation fails.B An exception is thrown at runtime.C The code executes normally and prints „foo”.D The code executes normally, but nothing is printed.
单选题2. public class Foo implements Runnable ( 3. public void run (Thread t) { 4. system.out.printIn(“Running.”); 5. } 6. public static void main (String[] args) { 7. new thread (new Foo()).start(); 8. ) 9. ) 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.
单选题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?()A A doneB B doneC A done B doneD B done A doneE There is no exception that the application will print anything.F The application outputs “A done” and “B done”, in no guaranteed order.
多选题class Order implements Runnable { public void run() { try { Thread.sleep(2000); } catch (Exception e) { } System.out.print("in "); } public static void main(String [] args) { Thread t = new Thread(new Order()); t.start(); System.out.print("pre "); try { t.join(); } catch (Exception e) { } System.out.print("post "); } } 可产生哪两项结果?()Ain preBpre inCin pre postDpre in post
单选题5. class Order2 implements Runnable { 6. public void run() { 7. for(int x = 0; x 〈 4; x++) { 8. try { Thread.sleep(100); } catch (Exception e) { } 9. System.out.print("r"); 10. } } 11. public static void main(String [] args) { 12. Thread t = new Thread(new Order2()); 13. t.start(); 14. for(int x = 0; x 〈 4; x++) { 15. // insert code here 16. System.out.print("m"); 17. } } } 哪一个插入到第15行,最有可能产生输出 rmrmrmrm ?()AThread.sleep(1);BThread.sleep(100);CThread.sleep(1000);Dtry { Thread.sleep(100); } catch (Exception e) { }
单选题现有: class ThreadExcept implements Runnable { public void run() { throw new RuntimeException("exception "); } public static void main(String [] args) { new Thread(new ThreadExcept()).start(); try { int x = Integer.parseInt(args[0]); Thread.sleep(x); System.out.print("main "); } catch (Exception e) { } } } 和命令行: java ThreadExcept 1000 哪一个是结果?()A mainB 编译失败C 代码运行,但没有输出D main java.lang.RuntimeException: exception