//class Fruit {
private String name; // 水果名
private String taste; //水果味道
private String producingArea; //水果产地
public Fruit(){}
public Fruit(String name,String taste,String producingArea){
this.name=name;
this.taste=taste;
this.producingArea=producingArea;
}
public void setName(String name) {
this.name = name;
}
public String getName(){
return name;
}
public void setTaste(String taste){
this.taste=taste;
}
public String getTaste(){
return taste;
}
public void setProducingArea(String producingArea){
this.producingArea=producingArea;
}
public String getProducingArea(){
return producingArea;
}
public void show(){
System.out.println("水果名:"+name+"\n产地:"+producingArea+"\n味道:"+taste);
}
}
class Sweet extends Fruit {
public Sweet(){}
public Sweet(String name,String taste,String producingArea){
super(name,taste,producingArea);
}
}
class DemoApple {
public static void main(String[] args) {
Sweet a = new Sweet("苹果","酸的","四川");
a.show();
System.out.println("---------------------");
Sweet a2 = new Sweet();
a2.setName("草莓");
a2.setTaste("酸");
a2.setProducingArea("马来西亚");
System.out.println("产地:"+a2.getProducingArea()+"\n水果名:"+a2.getName()+"\n口味:"+a2.getTaste());
}
}
|
|