【正确答案】class subThreadl implements Runnable //线程1
{
Thread threadl=new Thread (this,"1") ;
public void run() //重写 run()方法,输出 1~26
{
System. out.println ("线程: "+thread1. getName () +"开始运行! ") ;
for (int i=1; i<=26; i++)
{
System.out.println(i) ;
try
{
threadl.sleep(100) ;
}
catch (InterruptedException e)
{
System.out.println ("线程1异常") ;
}
}
}
}
class J02_Runnable implements Runnable //线程2
{
Thread thread2=new Thread(this,"2");
public void run() //重写 run()方法,输出 A~Z
{
System. out.println ("线程: "+thread2.getName () +"开始运行! ") ;
for(char ch='A';ch<='Z';ch++)
{
System. out.println(ch) ;
try
{
thread2.sleep(10);
}
catch(InterruptedException e)
{
System.out.println("线程2异常:") ;
}
}
}
public static void main(String[] args)
{
Thread threadl:new Thread(new subThreadl()) ; //线程1
threadl.start();
Thread thread2=new Thread(new J02 Runnable()); //线程2
thread2.start();}}
【答案解析】