河南成教 / Java程序设计
[填空题] 下面程序段是用Thread子类实现多线程(其中ThreadB与ThreadA非常相似,未给出)。
import java.util.Date;
public class Class3105
{
class ThreadA extends Thread
{
public void run()
{
Date timeNow;
for(int i=0;i<=5;i++)
{
timeNow=new Date();
System.out.println("A"+timeNow.toString());
try{sleep(2000);}
catch(InterruptedException e){}
}
}
}
class ThreadB extends Thread
{…………
…………
}
public Class3105()
{
ThreadA threadA=
ThreadB threadB=new ThreadB();
threadA.start();
}
public static void main(String[] args)
{
new Class3105();
}
}
import java.util.Date;
public class Class3105
{
class ThreadA extends Thread
{
public void run()
{
Date timeNow;
for(int i=0;i<=5;i++)
{
timeNow=new Date();
System.out.println("A"+timeNow.toString());
try{sleep(2000);}
catch(InterruptedException e){}
}
}
}
class ThreadB extends Thread
{…………
…………
}
public Class3105()
{
ThreadA threadA=
ThreadB threadB=new ThreadB();
threadA.start();
}
public static void main(String[] args)
{
new Class3105();
}
}
参考答案:
佳题速递: