62 lines
1.7 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cn.vscoder.experiment_2;
/**
* * 7.定义玩具类Toy继承自Product。
* * 8.添加玩具特有的属性型号String、材料String、安全级别String
* * 9.实现设置和获取这些属性的方法如setModel(String model)、getMaterial()等。
* * 10.重写toString()方法,输出玩具的完整信息。
*/
public class Toy extends Product {
private String model; // 型号
private String material; // 材料
private String security_level; // 安全级别
@Override
public String toString() {
return super.toString() +
", 型号='" + model + '\'' +
", 材料='" + material + '\'' +
", 安全级别='" + security_level + '\'' +
'}';
}
public Toy( String product_name, Double product_price, String product_producer, String product_color,
String product_weight, String model, String material, String security_level) {
super( product_name, product_price, product_producer, product_color, product_weight);
this.model = model;
this.material = material;
this.security_level = security_level;
}
public Toy() {
super();
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getMaterial() {
return material;
}
public void setMaterial(String material) {
this.material = material;
}
public String getSecurity_level() {
return security_level;
}
public void setSecurity_level(String security_level) {
this.security_level = security_level;
}
}