zoukankan      html  css  js  c++  java
  • 继承1

     1 package com.hanqi.z1p1;
     2 
     3 public class Instrument {
     4 
     5     public void play()
     6     {
     7         System.out.println("弹奏乐器");
     8     }
     9     
    10     
    11     
    12 }
     1 package com.hanqi.z1p1;
     2 
     3 public class Wind extends Instrument {
     4 
     5     public void play()
     6     {
     7         System.out.println("弹奏Wind");
     8     }
     9     
    10     
    11     public void play2()
    12     {
    13         System.out.println("调用Wind的play2");
    14     }
    15     
    16 }
     1 package com.hanqi.z1p1;
     2 
     3 public class Brass extends Instrument{
     4 
     5     public void play()
     6     {
     7         System.out.println("弹奏Brass");
     8     }
     9     
    10     public void play2()
    11     {
    12         System.out.println("调用Brass的play2");
    13     }
    14     
    15     
    16     
    17 }
     1 package com.hanqi.z1p1;
     2 
     3 public class Music {
     4 
     5     
     6     public static void tune(Instrument i) 
     7     {
     8     i.play();    
     9     }
    10     
    11     
    12     public static void main(String[] args) {
    13         // TODO 自动生成的方法存根
    14 
    15         Wind w=new Wind();
    16         tune(w);
    17         Brass b =new Brass();
    18         tune(b);
    19         
    20         
    21         
    22         
    23         
    24     }
    25 
    26 }

    运行结果:

  • 相关阅读:
    闭包
    保存数据
    Browers Object Model
    JavaScript中的null和undefined
    魔法查询函数
    《黑客与画家》 读书感想
    CakePHP查询数据
    HDFS写入和读取流程
    回调函数
    JAVA中的指针
  • 原文地址:https://www.cnblogs.com/miss123/p/5517827.html
Copyright © 2011-2022 走看看