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
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、0
- B、1
- C、2
- D、3
相关考题:
下面程序段的输出结果是______。 class Test{ public static void main(String args[ ]){ MyThread t=new MyThread( ); t.displayOutput("t has been created"); t.start( ); } } class MyThread extends Thread{ public void display Output(String s){ System.out,println(s); } public void run( ){ displayOutput("t is running"); } }A.t has been created t is runningB.t has been createdC.t is runningD.编译错误
下面程序段的输出结果是( )。 class Test{ public s,tatic void main(String args[]){ MyThread t=new MyThread; displayOutput("t has been createD"); start; } } Class MyThread extends Thread{ public void displayOutput(String s){ System.out.println(s); } public void run{ displayOutput("t is running."); } }A. t has been created.B.t has been created. t is running.C.t is running.D.编译出错
下面程序段的输出结果是 class Test{ public static void main(String args[]){ MyThread t=new MyThread(); t.displayOutput("t has been created)); t.start(); } } class MyThread extends Thread{ public void displayOutput(String s){ System.out.println(s); } public void run(){ displayOutput(t is running."); } }A.t has been created.B.t has been created. t is running.C.t is running.D.编译出错
下面程序段的输出结果是 classTest{ public static void main(Stringargs[]){ MyThread t=new MyThread(); t.displayOutput(”t has been createD) ”); t.start(); } } Class MyThread extends Thread{ public void displayOutput(Strings){ System.out.println(S); } public void run(){ displayOutput(”t is running.”); } }A.thas been created. t is running.B.thas been createdC.t is running.D.编译出错
3下碳程序段的输出结果是( )。 class Test{ public static void main(Srting args[]){ MyThread t=new MyThread(); t.displayOutput("t has been created"); t.start(); } } class MyThread extends Thread{ public void displayOutput(String s){ SYStem.out.println(s); } public void run() { displayOutput("t is running."); } }A.t has been created.B.t has been created. t is running.C.t is running.D.编译出错
下面程序段的输出结果是 class Test{ public static void main(String args[]){ MyThread t=new MyThread(); t.displayOutput("t has been createD) "; t.start(); } } class MyThread extends Thread{ public void displayOutput(String s){ System.out.println(s); } public void nm(){ displayOutput("t is running."); }A.t has been created. t is running.B.t has been created.C.t is running.D.编译出错
阅读下面程序 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();
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 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?() A、 AAAB、 BBBC、 Compilation fails.D、 The code runs with no output.
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();
现有: class Thread2 implements Runnable { void run() { System.out.print("go "); } public static void main(String [] args) { Thread2 t2 = new Thread2(); Thread t = new Thread(t2); t.start(); } } 结果为:()A、 goB、 编译失败C、 代码运行,无输出结果D、 运行时异常被抛出
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”.
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) { }
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 ThreadBoth extends Thread implements Runnable { public void run(){ System.out.print("hi "); } public static void main(String [] args){ Thread t1 = new ThreadBoth(); Thread t2 = new Thread(t1); t1.run(); t2.run(); } } 结果为:() A、hiB、hi hiC、编译失败D、代码运行,但无输出结果
1. public class enclosingone ( 2. public class insideone{} 3. ) 4. public class inertest( 5. public static void main (string[]args)( 6. enclosingone eo= new enclosingone (); 7. //insert code here 8. ) 9. ) Which statement at line 7 constructs an instance of the inner class?() A、 InsideOnew ei= eo.new InsideOn();B、 Eo.InsideOne ei = eo.new InsideOne();C、 InsideOne ei = EnclosingOne.new InsideOne();D、 EnclosingOne.InsideOne ei = eo.new InsideOne();
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
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 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?()A AAAB BBBC Compilation fails.D The code runs with no output.
单选题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.
单选题现有: class Thread2 implements Runnable { void run() { System.out.print ("go¨); } public static void main(String [] args) { Thread2 t2=new Thread2(); Thread t=new Thread(t2); t.start(); } } 结果为:()AgoB运行时异常被抛出C代码运行,无输出结果D编译失败
单选题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 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) { }
单选题1. public class enclosingone ( 2. public class insideone{} 3. ) 4. public class inertest( 5. public static void main (string[]args)( 6. enclosingone eo= new enclosingone (); 7. //insert code here 8. ) 9. ) Which statement at line 7 constructs an instance of the inner class?()A InsideOnew ei= eo.new InsideOn();B Eo.InsideOne ei = eo.new InsideOne();C InsideOne ei = EnclosingOne.new InsideOne();D EnclosingOne.InsideOne ei = eo.new InsideOne();