网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
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?()
- A、 Cat
- B、 Dog
- C、 Compilation fails.
- D、 The code runs with no output.
- E、 An exception is thrown at runtime.
参考答案
更多 “ 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?() A、 CatB、 DogC、 Compilation fails.D、 The code runs with no output.E、 An exception is thrown at runtime.” 相关考题
考题
当使用SomeThread t=new SomeThread()创建一个线程时,下列叙述中正确的是( )。A.SomeThread类是包含run()方法的任意Java类B.SomeThread类一定要实现Runnable接口C.SomeThread类是Thread类的子类D.SomeThread类是Thread类的子类并且要实现Runnable接口
考题
( 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 ()
考题
通过实现Rmmable接口创建线程,请在下面横线处填写代码完成此程序。public class ThreadTest{public static void main(String args []){Thread testObj1 = new Thread (new Hello ());Thread testObj2 = new Thread (new Hello ());testObj 2.start ( );}}class Hello implements Runnable{int j;public void run(){System.out.println("Hello" + j ++);}}
考题
如果使用 Thread t = new Test() 语句创建一个线程,则下列叙述正确的是A)Test 类一定要实现 Runnable 接口B)Test 类一定是 Thread 类的子类C)Test 类一定是 Runnable 的子类D)Test 类一定是继承 Thread 类并且实现 Runnable 接口
考题
请阅读下面程序 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()
考题
请完成下列Java程序:程序的功能演示了如何通过实现Runnable接口创建线程对象,程序中定义了一个类B,类中重写了含一个字符串参数的构造方法,并实现了Runnable接口,即在类B中编写了接口中的run()方法的方法体。还定义了一个应用程序类ex35_2,其中创建类B的3个对象b1,b2和b3作为线程对象t1,t2和t3的参数,并启动这3个线程。注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。程序运行结果如下:public class ex35_2{public static void main(String args[ ]){Runnable b1=new B("First");Runnable b2=new B("Second");Runnable b3=new B("Third");Thread t1=new Thread(b1);Thread t2=new Thread(b2);Thread t3=new Thread(b3);t1.start ();t2.start ();t3.start();}}class B _____________________ Runnable{String s;public B(String str){s=str;}_________________{for(int i=1;i<3;i++){System. out. println ( s+ "运行!");try{Thread.sleep((int) (Math.random() *100) );}catch (InterruptedException e){e.printStackTrace ( );}}System. out.println (s+"结束!");}}
考题
通过实现Runnable接口创建线程,请在下面横线处填入代码完成此程序。注意:不改动程序结构,不得增行或删行。class ThreadTest implements Runnable{Thread thrObj;public static void main(String args[]){System.out.println("这是一个通过实现接口创建线程的例子");ThreadTest testObj=new ThreadTest();testObj.create();}public void create(){if(thrObj= =null){thrObj=new Thread(this,"myThread");______}}public void run(){System.out.println("Thread"+throbj.getName()+":"+"在运行!");}}
考题
如果使用Thread t=new Test()语句创建一个线程,则下列叙述正确的是A.Test类一定要实现Runnable接口B.Test类一定是Thread类的子类C.Test类一定是Runnable的子类D.Test类一定是继承Thread类并且实现Runnable接口
考题
阅读下面程序 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();
考题
下列程序通过实现Runnable接口创建一个线程,选择正确的语句填入程序的横线处。 class MyRun implements Runnable { String str; MyRun(String s) { str = s; } public void run() System.out.println(str); } } public class ex40 { public static void main(String[] args) { String name = "实现阶段Runnable 接口"; MyRun my = new MyRun(name); Thread th = th. start ( ); } }A.new MyRun(my)B.new Thread()C.new Thread(my)D.Thread(my)
考题
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 Threads5 { public static void main (String[] args) { new Thread(new Runnable() { public void run() { System.out.print(”bar”); } }).start(); } } What is the result?() A、 Compilation fails.B、 An exception is thrown at runtime.C、 The code executes normally and prints “bar”.D、 The code executes normally, but nothing prints.
考题
Which two code fragments will execute the method doStuff() in a separate thread?()A、 new Thread() { public void run() { doStuff(); } }B、 new Thread() { public void start() { doStuff(); } }C、 new Thread() { public void start() { doStuff(); } } .run();D、 new Thread() { public void run() { doStuff(); } } .start();E、 new Thread(new Runnable() { public void run() { doStuff(); } } ).run();F、 new Thread(new Runnable() { public void run() { doStuff(); } }).start();
考题
public class Threads 1 { intx=0; public class Runner implements Runnable { public void run() { int current = 0; for(int=i=0;i4;i++){ current = x; System.out.print(current + “, “); x = current + 2; } } } public static void main(String[] args) { new Threads1().go(); } public void go() { Runnable r1 = new Runner(); new Thread(r1).start(); new Thread(r1 ).start(); } } Which two are possible results?()A、 0, 2, 4, 4, 6, 8, 10, 6,B、 0, 2, 4, 6, 8, 10, 2, 4,C、 0, 2, 4, 6, 8, 10, 12, 14,D、 0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,E、 0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
考题
现有: class ThreadBoth extends Threaa implements Runnable { public void run() (System.out.print("hi"); } public static voicl main (String [] args) { Thread tl=new ThreadBoth(): Thread t2 = new Thread (tl): tl.run(): t2.run(): } 结果为:() A、 hi hiB、 hiC、编译失败D、运行时异常被抛出
考题
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.
考题
Which two code fragments will execute the method doStuff() in a separate thread?()A、new Thread() {public void run() { doStuff(); }};B、new Thread() {public void start() { doStuff(); }};C、new Thread() {public void start() { doStuff(); }}.run();D、new Thread() {public void run() { doStuff(); }}.start();E、new Thread(new Runnable() {public void run() { doStuff(); }}).start();
考题
单选题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();A
Code block a.B
Code block B.C
Code block c.D
Code block d.E
Code block e.
考题
单选题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 Threads 1 { intx=0; public class Runner implements Runnable { public void run() { int current = 0; for(int=i=0;i4;i++){ current = x; System.out.print(current + “, “); x = current + 2; } } } public static void main(String[] args) { new Threads1().go(); } public void go() { Runnable r1 = new Runner(); new Thread(r1).start(); new Thread(r1 ).start(); } } Which two are possible results?()A0, 2, 4, 4, 6, 8, 10, 6,B0, 2, 4, 6, 8, 10, 2, 4,C0, 2, 4, 6, 8, 10, 12, 14,D0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,E0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,
考题
单选题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?()A
CatB
DogC
Compilation fails.D
The code runs with no output.E
An exception is thrown at runtime.
考题
单选题当使用SomeThread t=new SomeThread()创建一个线程时,下列叙述中正确的是( )。A
SomeThread类是包含run()方法的任意java类B
SomeThread类一定要实现Runnable接口C
SomeThread类是Thread类的子类D
SomeThread类是Thread类的子类并且要实现Runnable接口
考题
多选题Which two code fragments will execute the method doStuff() in a separate thread?()Anew Thread() { public void run() { doStuff(); } }Bnew Thread() { public void start() { doStuff(); } }Cnew Thread() { public void start() { doStuff(); } } .run();Dnew Thread() { public void run() { doStuff(); } } .start();Enew Thread(new Runnable() { public void run() { doStuff(); } } ).run();Fnew Thread(new Runnable() { public void run() { doStuff(); } }).start();
考题
多选题Which two can be used to create a new Thread?()AExtend java.lang.Thread and override the run method.BExtend java.lang.Runnable and override the start method.CImplement java.lang.thread and implement the run method.DImplement java.lang.Runnable and implement the run method.EImplement java.lang.Thread and implement the start method.
考题
单选题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?()A
Compilation fails.B
An exception is thrown at runtime.C
The code executes normally and prints “bar”.D
The code executes normally, but nothing prints.
考题
单选题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.
热门标签
最新试卷