2020-08-11

package fruits;

public class Fruits {
	private String shape;

	private String taste;

	public String getShape() {
		return shape;
	}

	public void setShape(String shape) {
		this.shape = shape;
	}

	public String getTaste() {
		return taste;
	}

	public void setTaste(String taste) {
		this.taste = taste;
	}

	public Fruits() {
		super();
	}

	public Fruits(String shape, String taste) {
		super();
		this.setShape(shape);
		this.setTaste(taste);
	}

	public void eat() {
		System.out.println("水果可供人们食用!");
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		} else {
			Fruits fruits = (Fruits) obj;
			if (this.getShape().equals(fruits.getShape())
					&& this.getTaste().equals(fruits.getTaste())) {
				return true;
			} else {
				return false;
			}
		}
	}
}

package fruits;

public final class Waxberry extends Fruits {
	private String color;

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	public Waxberry() {
		super();
	}

	public Waxberry(String shape, String taste, String color) {
		super(shape, taste);
		this.setColor(color);
	}

	public final void face() {
		System.out.println("杨梅:" + this.getColor() + "、" + this.getShape()
				+ "," + "果味" + this.getTaste() + "。");
	}

	@Override
	public void eat() {
		System.out.println("杨梅酸甜适中,非常好吃!");
	}

	@Override
	public String toString() {
		String str = "杨梅的信息:果实为" + this.getShape() + "、" + this.getColor()
				+ "," + this.getTaste() + ",非常好吃!";
		return str;
	}

}

package fruits;

public class Banana extends Fruits {
	private String variety;

	public String getVariety() {
		return variety;
	}

	public void setVariety(String variety) {
		this.variety = variety;
	}

	public Banana() {
		super();
	}

	public Banana(String shape, String taste, String variety) {
		super(shape, taste);
		this.setVariety(variety);
	}

	public void advantage() {
		System.out.println(this.getVariety() + "过形" + this.getShape() + ",过肉"
				+ this.getTaste() + ",可供审食。");
	}

	public void advantage(String color) {
		System.out.println(this.getVariety() + "颜色为" + color);
	}

}


package test;

import fruits.Banana;
import fruits.Fruits;
import fruits.Waxberry;

public class Test {
	public static void main(String[] args) {
		Fruits fru1 = new Fruits("圆形", "酸甜适中");
		Fruits fru2 = new Fruits("圆形", "酸甜适中");
		fru1.eat();
		System.out.println("fru1和fru2的引用比较:" + fru1.equals(fru2));
		System.out.println("————————————————————————————————————");
		Waxberry wb = new Waxberry("圆形", "酸甜适中", "紫红色");
		wb.face();
		wb.eat();
		System.out.println(wb);
		System.out.println("————————————————————————————————————");
		Banana banana = new Banana("短而稍圆", "香甜", "仙人蕉");
		banana.advantage();
		banana.advantage("黄色");
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值