程序员想要创建一个名为MyThread的类以便在main方法中用Thread实例化。对于下面三行: MyThread必须继承Thread。 MyThread必须实现Thread。 MyThread必须覆盖public void run()。 有几行是正确的?()
第1题:
请阅读下面程序 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()
第2题:
创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承Thread类,二是向Thread类传递一个Runnable对象。请在下面程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class TestThread{
public static void main(String args[ ])
{
MyThread t=new MyThread();
_______________________
}
}
class MyThread_____________Thread{
_____________________
{
for(int i=0;i<10;i++){
System.out.println(" " +i);
}
}
}
第3题:
通过实现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()+":"+"在运行!");
}
}
第4题:
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.编译出错
第5题:
阅读下面程序 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();
第6题:
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?()
第7题:
Which two code fragments will execute the method doStuff() in a separate thread?()
第8题:
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行,有几个可以通过编译?()
第9题:
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?()
第10题:
0
1
2
3
第11题:
0
1
2
3
第12题:
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();
第13题:
下列哪个方法可用于创建一个可运行的类? ( )
A.public class X implements Runable {public void run(){...,.,}}
B.public class X implements Thread {public void run(){......}}
C.public class X implements Thread {public int run(){……}}
D.public class X implements Runable {protected void run(){.....}}
第14题:
A.0
B.1
C.2
D.3
第15题:
下面程序段的输出结果是 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.编译出错
第16题:
下面程序段的输出结果是 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.编译出错
第17题:
A、声明Thread类的子类,创建Thread子类的实例,让线程调用start()方法
B、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例
C、创建Thread子类的实例,让线程调用start()方法
D、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例,让线程调用start()方法
第18题:
关于线程的创建过程,下面四种说法正确的有哪些?()
第19题:
程序员想要创建一个名为MyThread的类以便在main方法中用Thread实例化。对于下面三行: MyThread必须继承Thread。 MyThread必须实现Thread。 MyThread必须覆盖public void run()。 有几行是正确的?()
第20题:
Which two code fragments will execute the method doStuff() in a separate thread?()
第21题:
AAA
BBB
Compilation fails.
The code runs with no output.
第22题:
定义Thread类的子类,重写Thread类的run()方法,创建该子类的实例对象,调用对象的start()方法
定义Thread类的子类,重写Thread类的run()方法,创建该子类的实例对象,调用对象的run()方法
定义一个实现Runnable 接口的类并实现run()方法,创建该类实例对象,将其作为参数传递给Thread类的构造方法来创建Thread对象,调用Thread对象的start()方法
定义一个实现Runnable 接口的类并实现run()方法,创建该类对象,然后调用run()方法
第23题:
public void DoWork();
public void DoWork(int nCounter);
public void DoWork(object oCounter);
public void DoWork(Delegate oCounter);
第24题:
0
1
2
3