商品类继承输出问题
输出结果有问题,帮忙看一下public class Goods {
private int number;
private String name;
private String time;
private String manufacturer;
public Goods(int number,String name,String time,String manufacturer){
this.number=number;
this.name=name;
this.time=time;
this.manufacturer=manufacturer;
}
public String toString(){
String info="商品编号:"+number+"\t"+"商品名称:"+name+"\t"+"出厂日期:"+time+"\t"+"生产厂家:"+manufacturer+"\t";
return info;
}
}
class Food extends Goods{
private String storage;
private String ingredient;
public Food(int number,String name,String time,String manufacturer,String storage,String ingredient){
super(number,name,time,manufacturer);
this.storage=storage;
this.ingredient=ingredient;
}
public String toString(){
String info=super.toString()+"保质期:"+storage+"\t"+"主要成分:"+ingredient;
return info;
}
}
class Clothes extends Goods {
private String size;
private String fabrics;
public Clothes(int number,String name,String time,String manufacturer,String size,String fabrics){
super(number,name,time,manufacturer);
this.size=size;
this.fabrics=fabrics;
}
public String toString(){
String info=super.toString()+"服装尺寸:"+size+"\t"+"服装面料:"+fabrics;
return info;
}
}
public class GoodTest {
public static void main(String[] args){
Goods food=new Food(100034,"凤梨酥","2017年2月16日","北京食品厂","12个月","面粉和菠萝酱");
System.out.println(food);
Goods clothes=new Food(100067,"夹克","2017年1月26日","北京食服装厂","XL","棉和涤纶");
System.out.println(clothes.toString());
}
}
商品编号:100034 商品名称:凤梨酥 出厂日期:2017年2月16日 生产厂家:北京食品厂 保质期:12个月 主要成分:面粉和菠萝酱
商品编号:100067 商品名称:夹克 出厂日期:2017年1月26日 生产厂家:北京食服装厂 保质期:XL 主要成分:棉和涤纶