老师给点意见
package jicheng.one1;
public class four1 {
private String shape;
private String taste;
public four1() {}
public four1(String shape,String taste) {
this.setShape(shape);
this.setTaste(taste);
}
public void setShape(String shape) {
this.shape=shape;
}
public String getShape() {
return this.shape;
}
public void setTaste(String taste) {
this.taste=taste;
}
public String getTaste() {
return this.taste;
}
public void eat() {
System.out.println("水果可供人们使用");
}
public boolean equals(Object obj) {
if(obj==null)
return false;
four1 scc=(four1)obj;
if(this.getShape().equals(scc.getShape())&&this.getTaste().equals(scc.getTaste()))
return true;
else
return false;
}
public boolean equals(four1 obj) {
if(obj==null)
return false ;
if(this.getShape().equals(obj.getShape())&&this.getTaste().equals(obj.getTaste()))
return true;
else
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}package jicheng.one1;
public final class four2 extends four1 {
private String color;
public four2() {}
public four2(String color,String shape,String taste) {
this.setColor(color);
this.setShape(shape);
this.setTaste(taste);
}
public void setColor(String color) {
this.color=color;
}
public String getColor() {
return color;
}
public final void face() {
System.out.println("杨梅"+this.getColor()+this.getShape()+this.getTaste());
}
public void eat() {
System.out.println("杨酸梅甜适中,非常好吃");
}
public String toString() {
return this.getShape()+" "+this.getColor()+" "+this.getTaste();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}package jicheng.one1;
public class four3 extends four1 {
private String variety;
public four3() {}
public four3(String variety,String shape) {
this.setVariety(variety);
super.setShape(shape);
}
public void setVariety(String variety) {
this.variety=variety;
}
public String getVariety() {
return variety;
}
public void advantage() {
System.out.println(this.getVariety()+"果型"+this.getShape()+",果肉香甜,可供食");
}
public void advantage(String color) {
System.out.println(this.getVariety()+"颜色为"+color);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}package jicheng.one2;
import jicheng.one1.*;
public class Ce4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
four1 one=new four1("圆形","果味酸甜");
four1 two=new four1("圆形","果味酸甜");
one.eat();
System.out.println("one与two比较"+one.equals(two));
System.out.println("________________________________________________________________________");
four2 sc1=new four2("紫红色","圆形","果味酸甜适中");
sc1.face();
sc1.eat();
System.out.println(sc1);
System.out.println(sc1.toString());
System.out.println("________________________________________________________________________");
four3 sc2=new four3("仙人蕉","短而稍园");
sc2.advantage();
sc2.advantage("黄色");
}
}4
收起
正在回答 回答被采纳积分+1
1回答
2023版Java工程师
- 参与学习 人
- 提交作业 8788 份
- 解答问题 9886 个
综合就业常年第一,编程排行常年霸榜,北上广深月薪过万! 不需要基础,无需脱产即可学习,只要你有梦想,想高薪! 全新升级:技术栈升级(包含VUE3.0,ES6,Git)+项目升级(前后端联调与功能升级)
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星