1public abstract class Product {
2
3 protected String name;// 品名
4 protected LocalDate producedDate;// 生产日期
5 protected float price;// 价格
6
7 public Product(String name, LocalDate producedDate, float price) {
8 this.name = name;
9 this.producedDate = producedDate;
10 this.price = price;
11 }
12
13 public String getName() {
14 return name;
15 }
16
17 public void setName(String name) {
18 this.name = name;
19 }
20
21 public LocalDate getProducedDate() {
22 return producedDate;
23 }
24
25 public void setProducedDate(LocalDate producedDate) {
26 this.producedDate = producedDate;
27 }
28
29 public float getPrice() {
30 return price;
31 }
32
33 public void setPrice(float price) {
34 this.price = price;
35 }
36
37}
1public class Candy extends Product {// 糖果类
2
3 public Candy(String name, LocalDate producedDate, float price) {
4 super(name, producedDate, price);
5 }
6
7}
1public class Wine extends Product {// 酒类
2
3 public Wine(String name, LocalDate producedDate, float price) {
4 super(name, producedDate, price);
5 }
6
7}
1public class Fruit extends Product {// 水果
2 private float weight;
3
4 public Fruit(String name, LocalDate producedDate, float price, float weight) {
5 super(name, producedDate, price);
6 this.weight = weight;
7 }
8
9 public float getWeight() {
10 return weight;
11 }
12
13 public void setWeight(float weight) {
14 this.weight = weight;
15 }
16
17}