zoukankan      html  css  js  c++  java
  • 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("别说话!认真思考!");
    }
    }

  • 相关阅读:
    mysql批量替换指定字符串
    php中英字符串截取
    比较两个JSON字符串是否完全相等
    Java FastJson 介绍
    线程池
    DBUS及常用接口介绍
    在Mac中如何正确地设置JAVA_HOME
    base64 原理
    sizeof与strlen的区别
    Kubernetes 部署失败的 10 个最普遍原因
  • 原文地址:https://www.cnblogs.com/lvzhiqi/p/10816919.html
Copyright © 2011-2022 走看看