5月5号打卡
java的继承
package Music;
public class Music {
public void tune(Instrument i){
i.play();
}
public static void main(String args[]){
Music a=new Music();
Instrument d=new Instrument();
a.tune(d);
Wind b =new Wind();
b.play2();
a.tune(b);
Brass c=new Brass();
a.tune(c);
c.play2();
}
}
package Music;
public class Instrument {
public void play() {
// TODO 自动生成的方法存根
System.out.println("弹奏乐器");
}
}
class Wind extends Instrument{
public void play(){
System.out.println("弹奏Wind");
}
public void play2(){
System.out.println("调用wind的play2");
}
}
class Brass extends Instrument{
public void play(){
System.out.println("弹奏brass");
}
public void play2(){
System.out.println("调用brass的play2");
}
}
public class E {
public void main(String[] args) {
// TODO 自动生成的方法存根
Monkey b =new Monkey();
b.speak();
Poeple c =new Poeple();
c.speak();
c.think();
}
}
class Monkey {
public void speak(){
System.out.println("咿咿呀呀......");
}
}
class Poeple extends Monkey{
public void speak(){
System.out.println("小样的,不错嘛!会说话了!");
}
public void think(){
System.out.println("别说话!认真思考!");
}
}