更多"通过继承Thread创建线程,在主控程序中同时运行两个线程Thread"的相关试题:
[填空题]通过继承Thread创建线程,在主控程序中同时运行两个线程Thread1和Thread2。请在下面横线处填入代码完成此程序。
public class ThreadTest
{
public static void main(String args[])
{
new TestThread("Threadl").start( );
【7】
}
}
class TestThread extends Thread( )
{
public TestThread(String str)
{
super (str);
}
public void run( )
{
for(int i = 0; i<’5; i++)
{
System.out.println(i + .... + getName( ) + "在运行");
try
{
Sleep(1000);
}catch(InerruptedException e) {}
}
System.out.println(getName( ) + "已结束");
}
[填空题]在多线程程序设计中,如果采用继承Thread类的方式创建线程,则需要重写Thread类的______( )方法。
[简答题]创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承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);
[填空题]提供线程体的特定对象是在创建线程时指定的;创建线程对象是通过调用 【6】 类的构造方法实现的。
[填空题]当使用Thread t=new Thread(r)创建一个线程时,表达式:r instranceof Thread的值是______。
[填空题]当使用Thread t=new Thread(r)创建一个线程时,表达式:r instanceof Thread的值是______。