public class Instrument {
public void play(){
System.out.println("instrument is playing");
}
}
public class Piano extends Instrument{
public void play(){
System.out.println("piano is playing");
}
}
public class Violin extends Instrument{
public void play(){
System.out.println("voilin is playing");
}
}
测试:
public class InstrumentTest(){
public static void main(String[] args) {
Instrument instrument = new Piano();
instrument.play();
instrument = new Violin();
instrument.play();
}
}
class Instrument{
private String type;
Instrument(String type){
this.type = type;
}
public String play(){
System.out.println("Playing the"+type);
}
}
public class InstrumentTest{
public static void main(String args[]){
//test piano
System.out.println(new Instrument("Piano"));
//test violin
System.out.println(new Instrument("Violin"));
}
}
哥们这玩意你还是去专业论坛问吧、 塞班什么的都不错