zoukankan      html  css  js  c++  java
  • 类的继承和多态性-编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 getLegs(),设置动物名称的方法 setKind(),获得动物名称的方法 getKind(),获得动物数量的方法 getCount()。定义Fish类,是Animal类的子类,

    编写Java应用程序,定义Animal类,此类中有动物的属性:名称 name,腿的数量legs,统计动物的数量 count;方法:设置动物腿数量的方法 void setLegs(),获得腿数量的方法 getLegs(),设置动物名称的方法 setKind(),获得动物名称的方法 getKind(),获得动物数量的方法 getCount()。定义Fish类,是Animal类的子类,统计鱼的数量 count,获得鱼数量的方法 getCount()。定义Tiger类,是Animal类的子类,统计老虎的数量 count,获得老虎数量的方法 getCount()。定义SouthEastTiger类,是Tiger类的子类,统计老虎的数量 count,获得老虎数量的方法 getCount()。

    package hanqi;
    
    public class Animal {
        
        private String name;
        private int legs;
        private int count;
        
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getLegs() {
            return legs;
        }
        public void setLegs(int legs) {
            this.legs = legs;
        }
        public int getCount() {
            return count;
        }
        public void setCount(int count) {
            this.count = count;
        }
        
        
        
    }
    package hanqi;
    
    public class Fish extends Animal{
        private int count;
    
        public int getCount() {
            return count;
        }
    
        public void setCount(int count) {
            this.count = count;
        }
        
        
    
    }
    package hanqi;
    
    public class Tiger extends Animal{
        
        private int count;
    
        public int getCount() {
            return count;
        }
    
        public void setCount(int count) {
            this.count = count;
        }
    
    }
  • 相关阅读:
    MongoDB权限验证
    【大型网站开发系列第一篇】——网站结构层次
    php5.4的htmlspecialchars处理中文
    将session值字符串重新生成session
    php支持短标签
    solr suggest+autocomplete实现自动提示
    linux命令
    【技术】【转】字节序问题大端法小端法
    eeePC(易PC)变态测试!(上)
    "挑iPod不问价"就是不懂“性价比”?
  • 原文地址:https://www.cnblogs.com/zs6666/p/5901464.html
Copyright © 2011-2022 走看看