zoukankan      html  css  js  c++  java
  • 17、Java 三大特性之 多态

    java使 使

    1

    2

    class Animal{
       public int month = 2;
       public void eat(){
           System.out.println("西");
      }

    }

    class Dog extends Animal{
       public int month = 3;

       public void eat() {
           System.out.println("");
      }

       public void sleep() {
           System.out.println("");
      }
    }

    class Cat extends Animal{
       public int month = 4;

       public void eat() {
           System.out.println("");
      }
    }

    public class Test {
       public static void main(String[] args){
           Animal a = new Dog();
           Animal b = new Cat();
           a.eat();
           System.out.println(a.month);
           //
    //       a.sleep();
           b.eat();
           System.out.println(b.month);

      }
    }

    aAnimalDog;

    bAnimalCat

    eatAnimaleat


    2

    2

    maina.sleep()aAnimalAnimalsleepsleep

    a,bmonth,2

    3java

    Java

    3.1.

     

    3.2.

     

     

    4

    1.:

    2.:   

    3.:[]

    4.:使  

    5.:[]

    5

       访使使

        


                    

    圈~

     注公众号

  • 相关阅读:
    解决springmvc报错,java.lang.IllegalArgumentException:No converter found for return value of type: class .......
    BidiMap MultiMap LazyMap
    双色球2013年统计,从网上爬虫出来的
    捡石子小游戏程序解析
    Linux常用命令--List of commands(附目录切换命令)
    格式化字符串
    有关循环
    使用python 3.x 对pythonchallenge-----8的解答过程
    使用python 3.x 对pythonchallenge-----7的解答过程
    使用python 3.x 对pythonchallenge-----6的解答过程
  • 原文地址:https://www.cnblogs.com/naimao/p/13353322.html
Copyright © 2011-2022 走看看