黑马程序员技术交流社区
标题:
自己编了个继承的案例,有不足的请指教
[打印本页]
作者:
森然
时间:
2015-11-8 22:25
标题:
自己编了个继承的案例,有不足的请指教
//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());
}
}
作者:
唐彬
时间:
2015-11-8 23:33
基础学的还可以哦~
作者:
森然
时间:
2015-11-9 22:38
唐彬 发表于 2015-11-8 23:33
基础学的还可以哦~
嘿嘿 过奖了
作者:
森然
时间:
2015-11-9 22:39
唐彬 发表于 2015-11-8 23:33
基础学的还可以哦~
嘿嘿,过奖了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2