首页 > 编程语言 > 详细

JAVA之多态性

时间:2014-10-20 11:24:49      阅读:238      评论:0      收藏:0      [点我收藏+]

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之多态性

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!