zoukankan      html  css  js  c++  java
  • 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("我是狗,我的叫声是汪汪!!");
            }
        }

  • 相关阅读:
    FJ省队集训DAY3 T1
    FJ省队集训DAY2 T2
    FJ省队集训DAY2 T1
    FJ省队集训DAY1 T1
    POJ 1225 Substrings
    BZOJ 2732 射箭
    Light OJ 1314 Names for Babies
    SPOJ220 Relevant Phrases of Annihilation
    POJ3683 Falsita
    ES6 常用语法
  • 原文地址:https://www.cnblogs.com/milantgh/p/4036133.html
Copyright © 2011-2022 走看看