早教吧作业答案频道 -->其他-->
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为什么...的网友还看了以下:
留步帮忙下这样定义是个什么方法 public static T CloneObject(this 2020-05-14 …
How muchj is this t-shirt?(改为同义句)——— ———the price 2020-05-16 …
首字母填空,p什么He sleep for less than 6 hours every day 2020-05-16 …
机械效率和功率好像有关,下面是我分析不知可否,机械功率=有用功/总功,而有用功=P有t,总功=P总 2020-06-19 …
设全集为I,若P并T=P(上面有一横杠)并S,则A.P并T并S=IB.P=T=S另外,P上面加一横 2020-07-08 …
用MATLAB,求p=0.1时,被积函数t*p*(1-p)^t*exp(p*(1-(1-p)^t) 2020-07-23 …
7、关于功率,下列说法正确的是A、由P=W/t,P与W成反比B、由P=W/t,p与t成正比C、由P= 2020-10-30 …
已知圆(x-5)^2+(y-5)^2=25,一个质点P从(0,5)开始在圆上做匀速圆周运动(逆时针方 2020-11-01 …
英语练习回答These(p什么)aregreat.就是括号内填的单词是p开头的.1These(p什么 2021-02-05 …
英文单词分类填空动物类1.O()t()p()s2.k()t()e()3.l()b()t()r4.a( 2021-02-05 …