Java 错误类User是公共的 书上是这样写的 为什么程序运行的时候显示有错?
classTalkPlace{staticStringtalkArea="";}publicclassUser{//显示这里有错错误User是公共的Stringname;...
class TalkPlace{
static String talkArea="";
}
public class User{ //显示这里有错 错误User是公共的
String name;
int age;
public User(String yourname,int yourage){
name= yourname;
age= yourage;
}
void speak(String words){
TalkPlace.talkArea=TalkPlace.talkArea+name+"?:"+words+"\n";
}
public static void main(String[] args){
User x1=new User("张三",20);
x1.speak("Hello!");
User x2=new User("李四",16);
x2.speak("good morning");
x1.speak("Bye");
}
} 展开
static String talkArea="";
}
public class User{ //显示这里有错 错误User是公共的
String name;
int age;
public User(String yourname,int yourage){
name= yourname;
age= yourage;
}
void speak(String words){
TalkPlace.talkArea=TalkPlace.talkArea+name+"?:"+words+"\n";
}
public static void main(String[] args){
User x1=new User("张三",20);
x1.speak("Hello!");
User x2=new User("李四",16);
x2.speak("good morning");
x1.speak("Bye");
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询