請問怎么會提示錯誤呢?
package com.xuanxuan;
public class Actor extends Thread {
public void run() {
System.out.println(getName()+"是一個演員");
int count=0;
boolean keepRuning=true;
while(keepRuning) {
System.out.println(getName()+"登臺演出"+(++count));
if(count==100) {
keepRuning=false;
}
if(count%10==0) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(getName()+"演出結束了");
}
class Actress implements Runnable{
public void run() {
System.out.println(Thread.currentThread().getName()+"是一個演員");
int count=0;
boolean keepRuning=true;
while(keepRuning) {
System.out.println(Thread.currentThread().getName()+"登臺演出"+(++count));
if(count==100) {
keepRuning=false;
}
if(count%10==0) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(Thread.currentThread().getName()+"演出結束了");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread actor=new Actor();
actor.setName("先生");
Thread actressThread=new Thread(new Actress(),"女士");
actor.start();
actressThread.start();
}
}
2019-07-03
class Actress implements Runnable{
public void run() {
System.out.println(Thread.currentThread().getName()+"是一個演員");
int count=0;
boolean keepRuning=true;
while(keepRuning) {
System.out.println(Thread.currentThread().getName()+"登臺演出"+(++count));
if(count==100) {
keepRuning=false;
}
if(count%10==0) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.out.println(Thread.currentThread().getName()+"演出結束了");
}
}
這個class Actress叫做內部類,他和public class Actor是同級的,所以Actress應該放在Actor的大括號的外面。
2019-06-13
Actress類放外面。不是放在Actor里面的
2019-04-24
在你的Actress類前面加個static