/**
* 乐器类
*/
public class Instrument {
//名称
private String name;
//重量
private String weight;
//品牌
private String brand;
//价格
private String price;
//无参构造
public Instrument() {
}
//表演方法
public void perform() {
System.out.println("表演方法");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getWeight() {
return weight;
}
public void setWeight(String weight) {
this.weight = weight;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
/**
* 钢琴类
*/
public class Piano extends Instrument{
//类型
private String type;
//制作年份
private String year;
//出产国
private String country;
//重写表演方法
public void perform() {
System.out.println("用手指轻轻敲击弹奏");
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
/**
* 小提琴类
*/
public class Violin extends Instrument{
//琴弦厂家
private String factory;
//制作者
private String maker;
//重写表演方法
public void perform() {
System.out.println("用琴弓轻轻拉动琴弦");
}
public String getFactory() {
return factory;
}
public void setFactory(String factory) {
this.factory = factory;
}
public String getMaker() {
return maker;
}
public void setMaker(String maker) {
this.maker = maker;
}
}
/**
* 测试类
*/
public class Test {
public static void main(String[] args) {
//钢琴表演
Piano p = new Piano();
p.perform();
//小提琴表演
Violin v = new Violin();
v.perform();
}
}