问答详情
源自:-

为什么我的代码和老师的一样就是报错!!!!!为什么


public class ActorCopy extends Thread

{

public void run()

{

System.out.println(getName()+"是一个演员!");

boolean keepRunning=true;

int count=0;

while(keepRunning)

{

System.out.println(getName()+"第"+(count+1)+"登台演出");

count++;

if(count==100)

 keepRunning=false;

if(count%10==0)

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

System.out.println(getName()+"结束演出!");

}

public static void main(String [] args)

{

Thread Actor=new ActorCopy();

Actor.setName("刘德华");

Actor.start();

Thread actressThread=new Thread(new Actress(),"汤唯");

actressThread.start();

}

class Actress implements Runnable

{


@Override

public void run() {

System.out.println(Thread.currentThread().getName()+"是一个女演员!");

Boolean keepRunning=true;

int count =0;

while(keepRunning)

{

System.out.println(Thread.currentThread().getName()+"第"+(count+1)+"次登台演出!");

count++;

if(count%10==0)

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

if(count ==100)

keepRunning=false;

}

System.out.println(Thread.currentThread().getName()+"结束演出!");

}

}

}



为什么我的代码和老师的一样就是报错!!!!!为什么


提问者:慕仰4084179 2015-11-11 17:37

个回答

  • 转变者
    2015-11-11 20:20:42
    已采纳

    这里不一样的呀!public class ActorCopy extends Thread

    class Actress implements Runnable