码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA之多态性

时间:2014-10-20 11:25:52      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:color   ar   java   sp   bs   new   as   class   ca   

package com.test;

//多态性

public class test4 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

  Animal an = new Cat();

  an.cry();

  an = new Dog();

  an.cry();
    }
}
    
    class Animal
    {
//        private String name;
//        
//        private String color;
//        
//        private float weight;
//        
        public void cry()
        {
            System.out.println("我是动物,我不知道怎么叫!!");
        }
    }
    
    class Cat extends Animal
    
    {
        public void cry()
        {
            System.out.println("我是猫,我的叫声是喵喵!!");
        }
    }
    
    class Dog extends Animal
    {
        public void cry()
        {
            System.out.println("我是狗,我的叫声是汪汪!!");
        }
    }

JAVA之多态性

标签:color   ar   java   sp   bs   new   as   class   ca   

原文地址:http://www.cnblogs.com/milantgh/p/4036641.html

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