码迷,mamicode.com
首页 > 其他好文 > 详细

5月5号打卡

时间:2019-05-05 23:26:19      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:调用   java   ras   new   static   自动生成   void   mon   ext   

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("别说话!认真思考!");
}
}

 

5月5号打卡

标签:调用   java   ras   new   static   自动生成   void   mon   ext   

原文地址:https://www.cnblogs.com/lvzhiqi/p/10816919.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!