早教吧作业答案频道 -->其他-->
javaeclipse为什么编译后显示ThepublictypeDollmustbedefinedinitsownfile我的程序:publicclassDoll{privateStringname;publicDoll(Stringname){this.name=name;}publicvoidspeak(){System.out.println(name);}}publicclassDoll
题目详情
java eclipse 为什么编译后显示The public type Doll must be defined in its own file
我的程序:
public class Doll{
private String name;
public Doll(String name) {
this.name = name;
}
public void speak(){
System.out.println(name);
}
}
public class DollApp{
public static void main(String[] args) {
// TODO Auto-generated method stub
Doll beibei = new Doll("贝贝");
Doll jingjing = new Doll("晶晶");
Doll huanhuan = new Doll("欢欢");
Doll yingying = new Doll("迎迎");
Doll nini = new Doll("妮妮");
beibei.speak();
jingjing.speak();
huanhuan.speak();
yingying.speak();
nini.speak();
}
}
太纠结了,
显示的错误信息是:
Exception in thread "main" java.lang.Error:Unresolved compilation problem:
The public type Doll must be defined in its own file
at Doll.(DollApp.java:2) 就是第一行 public class Doll{ 感觉是我Doll的命名问题
at DollApp.main(DollApp.java:19)
我的程序:
public class Doll{
private String name;
public Doll(String name) {
this.name = name;
}
public void speak(){
System.out.println(name);
}
}
public class DollApp{
public static void main(String[] args) {
// TODO Auto-generated method stub
Doll beibei = new Doll("贝贝");
Doll jingjing = new Doll("晶晶");
Doll huanhuan = new Doll("欢欢");
Doll yingying = new Doll("迎迎");
Doll nini = new Doll("妮妮");
beibei.speak();
jingjing.speak();
huanhuan.speak();
yingying.speak();
nini.speak();
}
}
太纠结了,
显示的错误信息是:
Exception in thread "main" java.lang.Error:Unresolved compilation problem:
The public type Doll must be defined in its own file
at Doll.(DollApp.java:2) 就是第一行 public class Doll{ 感觉是我Doll的命名问题
at DollApp.main(DollApp.java:19)
▼优质解答
答案和解析
两个类要分开写到不同的.java文件中
看了 javaeclipse为什么...的网友还看了以下:
为什么这一步lingo提出我missing right parenthesis的错误 实在看不出 2020-05-14 …
已知字母组合成英语单词1、e e t t i n h r 2、e e r a t w h 3、o 2020-05-14 …
Here is a small talk.A;You're new here,aren't you 2020-05-16 …
I don't think fast food is good for our heath,so 2020-05-16 …
英语翻译Cólẽtôiđitôibiếtbạnkhôngthíchquanđiểmcủatôiba 2020-06-07 …
复数和三角函数问题sin(i*x+t)能不能表示成不含i的形式?其中i是虚数单位我本来的想法是先展 2020-08-02 …
A:HelloHelen.B:26,Mike.A:How27you?B:Fine,28•Andyou 2020-10-30 …
functionf=myfun(x)矩阵定义省略forj=1:28a=0;fori=1;27;a=a 2020-11-01 …
求大神帮忙写一篇英文短文16句话每句依次以“H,O,W,I,S,T,I,L,L,L,O,V,E,Y, 2020-11-26 …
大家快近来,悬赏20哦写出以下英文的中文意思哦~~What'sthisinEnglish.It'sa 2020-11-28 …