JAVA之方法的重写

package com.test;

//方法重写(overwrite)

public class test3 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        //建立一只猫
        
        Cat cat = new Cat();
        
        //建立一只狗
        
        Dog dog = new Dog();
        
        //猫与狗的叫声
        
        cat.cry();
        
        dog.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("我是狗,我的叫声是汪汪!!");
        }
    }

原文地址:https://www.cnblogs.com/milantgh/p/4036133.html