对于下面语句的说法,不正确的是( )。Thread thrObj=new Thread:
A.系统没有为该线程对象分配资源
B.只能启动或者终止
C.创建了一个空的线程对象
D.可以调用其他方法
第1题:
语句Thread thread1=new SomeThreadClass()成功运行后,线程thread1处于生命周期的______状态。
第2题:
A.通过Thread类的构造方法创建线程
B.Thread类提供了start()方法创建线程
C.通过实现Runnable接口创建线程
D.通过使用Thread类提供的interrupt()方法创建线程
第3题:
对于下面语句的说法,不正确的是( )。Thread thrObj=new Thread( );
A.系统没有为该线程对象分配资源
B.只能启动或者终止
C.创建了-个空的线程对象
D.可以调用其他方法
第4题:
下列程序通过设定线程优先级,抢占主线程的CPU,选择正确的语句填入横线处。 class T14 implements Runnable { private Boolean fStop - true; public void run() { while(fStop) { System.out.println(Thread.currentThread().getName() + "run"); try { Thread.sleep(l); } catch(Exception e) { e.printStackTrace(); } } } public void stopRun() { fStop = false; } } public class Testl4 { public static void main(String[] args) { T14 t14 = new T14(); Thread t1 = new Thread(ti4, "T14"); Thread t = Thread.currentThread()'; ______; Ti.start(); T14.stopRun(); System.out.println ( "stop "); } }
A.setPriority(Thread. MIN_PRIORITY)
B.t1 .setPriority(Thread. MIN_PRIORITY)
C.t.setPfiofity(Thread. MIN_PRIORITY)
D.t14.setPriority(Thread. MIN_PRIORITY)
第5题:
下列程序的运行结果是______。 class A implements Runnable { int a; iht i = 2; A(int x) { a = x; } public void run() { while(i > 0) { System.out.println("线程" + a); i--; } } } public class Testl3 { public static void main(String[] args) { Thread a1 = new Thread(new A(1)); Thread a2 = new Thread(new A(2)); a1.start(); a2.start(); } }
A.线程1 线程1 线程2 线程2
B.线程1 线程2
C.线程1 线程2 线程1 线程2
D.线程1 线程1 线程1 线程1
第6题:
如果使用Thread t=new Test()语句创建一个线程,则下列叙述正确的是
A.Test类一定要实现Runnable接口
B.Test类一定是Thread类的子类
C.Test类一定是Runnable的子类
D.Test类一定是继承Thread类并且实现Runnable接口
第7题:
对于下面语句,不正确的说法是______。 Thread thrObj=new Thread( );
A.系统没有为此线程对象分配资源
B.只能启动或者终止
C.创建了一个空的线程对象
D.可以调用其他方法
第8题:
下列程序通过实现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)
第9题:
A、声明Thread类的子类,创建Thread子类的实例,让线程调用start()方法
B、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例
C、创建Thread子类的实例,让线程调用start()方法
D、声明Thread类的子类,在子类中重新定义run()方法,创建Thread子类的实例,让线程调用start()方法
第10题:
下面关于Java中线程的说法不正确的是()
第11题:
下面()让线程休眠1分钟。
第12题:
调用join()方法可能抛出异常InterruptedException。
sleep()方法是Thread类的静态方法。
调用Thread类的sleep()方法可终止一个线程对象。
线程启动后执行的代码放在其run方法中。
第13题:
请阅读下面程序 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()
第14题:
创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承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);
}
}
}
第15题:
通过实现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()+":"+"在运行!");
}
}
第16题:
对于下面语句的说法,不正确的是 Thread thrObj=new Thread();
A.系统没有为该线程对象分配资源
B.只能启动或者终止
C.创建了一个空的线程对象
D.可以调用其他方法
第17题:
下列程序的运行结果是______。 Class C14 implements Runnable { private int i; public C14(int n) { this.i = n; } public void run{) { try { Thread.currentThread().sleep(i); } catch(InterruptedException ie) { System.err.println(ie.tString()); } System.out.println("线程" + Thread.currentThread() .getName + "睡眠了" + i + "毫秒结束"); } } public class Testl4 { public static void main(String[] args) { Thread t = new Thread(new C14(300), "t"); t.start(); } }
A.线程t睡眠了300毫秒结束
B.线程Thread-0睡眠了300毫秒结束
C.线程t睡眠了i毫秒结束
D.线程Thread-0睡眠了i毫秒结束
第18题:
当使用SomeThread t=new SomeThread( )创建-个线程时,下列叙述中正确的是( )。
A.Some Thread类是包含run( )方法的任意Java类
B.Some Thread类-定要实现Runnable接口
C.Some Thread类是Thread类的子类
D.Some Thread类是Thread类的子类并且要实现Run-nable接口
第19题:
阅读下面程序 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();
第20题:
请阅读下面程序,说明该程序创建线程使用的方法是( )。 public class ThreadTest { public static void main(String args[]) { Thread tl=new Thread(new HolloWorld); Thread t2=new Thread(new HolloWorld); tl.start; t2.Start; } } class HolloWorld implements Runnable { int i; public void run { while(true) { System.out.println("HolloWorld"+i++); if(i= =5)break; } } }
A.继承Thread类
B.实现Runnable接口
C.tl.start
D.t2.start
第21题:
下列说法中错误的一项是 ( )
A.使用继承Thread类创建线程,可以直接调用线程的方法
B.通过实现Runnable接口创建线程,体现了面向对象的思想
C.Thread类从面向对象的角度看,是虚拟CPU的封装
D.通过实现Runnable接口创建线程,会影响Thread类的体系
第22题:
关于线程的创建过程,下面四种说法正确的有哪些?()
第23题:
定义Thread类的子类,重写Thread类的run()方法,创建该子类的实例对象,调用对象的start()方法
定义Thread类的子类,重写Thread类的run()方法,创建该子类的实例对象,调用对象的run()方法
定义一个实现Runnable 接口的类并实现run()方法,创建该类实例对象,将其作为参数传递给Thread类的构造方法来创建Thread对象,调用Thread对象的start()方法
定义一个实现Runnable 接口的类并实现run()方法,创建该类对象,然后调用run()方法
第24题: