myecplise运行正常 网上运行错误
来源:4-3 编程练习
言无月
2020-02-24 22:39:17
为什么在myecplise运行正常 在这里运行却出错
// 私有属性:品种(variety)
private String variety;
//创建带参构造方法为所有属性赋值
public Lab_20_Banana(){
}
public Lab_20_Banana(String variety,String shape,String taste){
super(shape, taste);
this.variety=variety;
}
//创建无参无返回值的advantage方法,描述为:**果形**,果肉香甜,可供生食。
public void advantage(){
System.out.println(variety+"果形"+getShape()+","+getTaste()+",可供生食。");
}
//创建重载advantage方法(带参数color),描述为:**颜色为**
public void advantage(String color){
System.out.println(variety+"颜色为"+color);
}
}
1回答
好帮手慕酷酷
2020-02-25
同学你好,如果将代码放在在线编译器上运行,因为在线编辑器的类名是固定的,如:

所以在编写构造方法时,构造方法名应该与类名一致。如:

同理,其他类也是一样的。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题
回答 2