编码需求:
乐器(Instrument)分为钢琴()和小提琴
各种乐器的弹奏 方法各不相同
编写一个测试类InstrumentTest要求
编写方法testplay,对各种乐器进行弹奏测试,要依据乐器的不同,进行相应的弹奏
乐器(Instrument)分为钢琴()和小提琴
各种乐器的弹奏 方法各不相同
编写一个测试类InstrumentTest要求
编写方法testplay,对各种乐器进行弹奏测试,要依据乐器的不同,进行相应的弹奏
在main方法中进行测试
package yee.instrument;
public class InstrumentTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Instrument instrument = new Piano();
instrument.play();
Instrument instrument2 = new Violin();
instrument2.play();
}
}
package yee.instrument;
public class Instrument {
public void play()
{
System.out.println("Instrument");
}
}
package yee.instrument;
public class Piano extends Instrument {
@Override
public void play() {
// TODO Auto-generated method stub
// super.play();
System.out.println("钢琴演奏");
}
}
package yee.instrument;
public class Violin extends Instrument {
@Override
public void play() {
// TODO Auto-generated method stub
// super.play();
System.out.println("小提琴演奏");
}
}
posted on
浙公网安备 33010602011771号