程序不能通过编译,因为没有import语句将Thread类引入
程序不能通过编译,因为Test类没有实现Runnable接口
程序通过编译,且运行正常,没有任何输出
程序通过编译,且运行正常,打印出一个"Hello"
第1题:
( 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 ()
第2题:
阅读下面程序
class Test implements Runnable{
public static void main(String[] args){
Test t = new Test();
t.start();
}
public void run(){ }
}
下列关于上述程序的叙述正确的是
A) 程序不能通过编译,因为 start() 方法在 Test 类中没有定义
B) 程序编译通过,但运行时出错,提示 start() 方法没有定义
C) 程序不能通过编译,因为 run() 方法没有定义方法体
D) 程序编译通过,且运行正常
第3题:
对下列程序的叙述中,正确的是
1:public class X extends Thread implements Runnable{
2:publ主c void run(){
3: System.out.println(“this is run()”);
4:}
5:public static void main(String args〔〕){
6:Threadt二new Thread(new X());
7:t.start();
8:}
9:}
A.第1行会产生编译错误
B.第6行会产生编译错误
C.第6行会产生运行错误
D.程序正常运行
第4题:
阅读下面程序 public class Test implements Runnable{ public static void main(String[]args){ _______________________________________; t. start(); } public void mR(){ System. out. println("Hello!"); }} 在程序下画线处填入正确选项是
A.Test t=flew Test()
B.Thread t=new Thread();
C.Thread t=new Thread(new Test());
D.Test t=new Thread();
第5题:
阅读下列程序:class ThreadTest extends Thread{ public static void main(String[]args){ Thread t=new Thread(this); t.start(); } public void run(){ System.out.print("A thread test."); }} 对该程序而言,正确结论是 ( )
A.该程序能够通过编译并打印输出“A thread test.”
B.该程序能够通过编译,但运行时将不调用ThreadTest类中的run()方法,因此不产生任何输出
C.该程序存在编译错误,因为在main()方法中不能使用this指针
D.上述选项都不正确
第6题:
通过实现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 ++);
}
}
第7题:
请阅读下面程序 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()
第8题:
阅读下列代码 public class Test implements Runnable{ public void run(Thread t){ System. out. println("Running. "); } public static void main(String[]args){ Thread tt=new Thread(new Test()); tt. start(); } } 代码运行结果是
A.将抛出一个异常
B.没有输出并正常结束
C.输出“Running”并正常结束
D.程序第2行将出现一个编译错误
第9题:
阅读下面代码 public class Test implements Runnable { public void run(Thread t) { System.out.println("Running"); } public static void main(String[] args) { Thread tt=new Thread(new Test()); tt.start(); } } 代码运行的结果是
A.将抛出一个异常
B.没有输出并正常结束
C.输出“Running”并正常结束
D.程序第2行将出现一个编译错误
第10题:
阅读下面程序 class Test implements Runnable { public static void main(String[] args) { Test t=new Test(); t.start(): } public void run() {} } 下列关于上述程序的叙述正确的是
A.程序不能通过编译,因为start()方法在Test类中没有定义
B.程序编译通过,但运行时出错,提示start()方法没有定义
C.程序不能通过编译,因为run()方法没有定义方法体
D.程序编译通过,且运行正常