网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
publicclassFooimplementsRunnable(publicvoidrun(Threadt){system.out.printIn(Running.”);}publicstaticvoidmain(Stringargs){newthread(newFoo()).start();})Whatistheresult?()

A.Anexceptionisthrown.

B.Theprogramexistswithoutprintinganything.

C.Anerroratline1causescompilationtofail.

D.Anerroratline6causesthecompilationtofail.

E.“Running”isprintedandtheprogramexits.


参考答案

更多 “ publicclassFooimplementsRunnable(publicvoidrun(Threadt){system.out.printIn(Running.”);}publicstaticvoidmain(Stringargs){newthread(newFoo()).start();})Whatistheresult?() A.Anexceptionisthrown.B.Theprogramexistswithoutprintinganything.C.Anerroratline1causescompilationtofail.D.Anerroratline6causesthecompilationtofail.E.“Running”isprintedandtheprogramexits. ” 相关考题
考题 ( 24 )请阅读下面程序public class ThreadTest {public static void main ( String args[ ]){Thread t1 = new Thread ( new Hello ()):Thread t2 = new Thread ( new Hello ()):t l .start ():t2.start ();}}class Hello implements Runnable {int i ;public void run (){while ( true ) {System.out.println ( "Hello"+i++ ) ;if ( i=5 ) break :}}}该程序创建线程使用的方法是()A )继承 Thread 类B )实现 Runnable 接口C ) t l.start ()D ) t2.start ()

考题 请阅读下面程序 public class ThreadTest{ public static void main(String args[]) ( Thread t1=new Thread(new Hello()); Thread t2=new Thread(new Hello()); t1.start(); t2.start(); } } class Hello implements Runnable { int i; public void run() { while(true) { System.out.prinfin("Hello"+i++); if(i=5) break; } } } 该程序创建线程使用的方法是A.继承Thread类B.实现Runnable接口C.t1.start()D.t2.start()

考题 Runnabler=newRunnable(){publicvoidrun(){System.out.print(”Cat”);}};Threadt=newThread(r){publicvoidrun(){System.out.print(”Dog”);}};t.start();Whatistheresult?() A.CatB.DogC.Compilationfails.D.Thecoderunswithnooutput.E.Anexceptionisthrownatruntime.

考题 publicclassThreads4{publicstaticvoidmain(String[]args){newThreads4().go();}publicvoidgo(){Runnabler=newRunnable(){publicvoidrun(){System.out.print(”foo”);}};Threadt=newThread(r);t.start();t.start();}}Whatistheresult?()A.Compilationfails.B.Anexceptionisthrownatruntime.C.Thecodeexecutesnormallyandprints?foo”.D.Thecodeexecutesnormally,butnothingisprinted.

考题 GiventhatastaticmethoddoIt()inaclassWorkrepresentsworktobedone,whatblockofcodewillsucceedinstartinganewthreadthatwilldothework?CODEBLOCKa:Runnabler=newRunnable(){publicvoidrun(){Work.doIt();}};Threadt=newThread(r);t.start();CODEBLOCKb:Threadt=newThread(){publicvoidstart(){Work.doIt();}};t.start();CODEBLOCKc:Runnabler=newRunnable(){publicvoidrun(){Work.doIt();}};r.start();CODEBLOCKd:Threadt=newThread(newWork());t.start();CODEBLOCKe:Runnablet=newRunnable(){publicvoidrun(){Work.doIt();}};t.run();

考题 publicclassFooimplementsRunnable(3.publicvoidrun(Threadt){4.system.out.printIn(Running.”);5.}6.publicstaticvoidmain(String[]args){7.newthread(newFoo()).start();8.)9.)Whatistheresult?() A.Anexceptionisthrown.B.Theprogramexistswithoutprintinganything.C.Anerroratline1causescompilationtofail.D.Anerroratline6causesthecompilationtofail.E.“Running”isprintedandtheprogramexits.

考题 publicclassFooimplementsRunnable(publicvoidrun(Threadt){system.out.printIn(Running.”);}publicstaticvoidmain(String[]args){newthread(newFoo()).start();})Whatistheresult?() A.Anexceptionisthrown.B.Theprogramexistswithoutprintinganything.C.Anerroratline1causescompilationtofail.D.Anerroratline2causesthecompilationtofail.E.“Running”isprintedandtheprogramexits.

考题 清阅读下面程序,说明该程序创建线程使用的方法是( )。 publicclassThreadTest { publicstaticvoidmain(Stringargs[]) { Threadt1=newThread(newHolloWorld()); Threadt2=newThread(newHolloWorld()); t1.start(); t2.start(); } } classHolloWorldimplementsRunnable { inti; publicvoidrun() { while(true) { System.out.println("HolloWorld"+i++); if(i==5)break; } } }A.继承Thread类B.实现Runnable接口C.t1.start()D.t2.stan()

考题 【单选题】请看下面未完成的代码 public class Foo implements Runnable { public void run (Thread t) { System.out.println("Running."); } public static void main (String[] args) { new Thread(new Foo()).start(); } } 结果是?A.运行时抛出一个异常B.程序能够运行,但是没有任何输出C.没有实现 Runnable 接口中的方法导致编译错误D.程序运行后输出“Running”