zoukankan      html  css  js  c++  java
  • 继承作业3

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

    package zuoye10;
    
    public class Animal {
    	
    	private String name;//名称
    	private int legs;//退的数量
    	public 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;
    	}//动物数量
    	public Animal() {
    		super();
    	}
    	
    	
    
    }
    

      

    package zuoye10;
    
    public class Fish extends Animal {
    	
    
    	public int getCount() {
    		return Count();
    	}
    	public void setCount(int count) {
    		this.count = count;
    	}
    }
    

      

    package zuoye10;
    
    public class Tiger extends Animal {
    
    	public int getCount() {
    		return Count();
    	}
    	public void setCount(int count) {
    		this.count = count;
    	}
    
    }
    

      

    package zuoye10;
    //东南虎
    public class SouthEastTiger extends Tiger {
    	
    
    	public int getCount() {
    		return Count();
    	}
    	public void setCount(int count) {
    		this.count = count;
    	}
    
    }
    

      

    package zuoye10;
    
    public class Ceshi_animal {
    
    
    	public static void main(String[] args)
    	{
    		Fish f=new Fish();
    		f.setName("鱼");
    		f.setCount(20);
    		f.setLegs(0);
    		System.out.println("动物的类型是:"+f.getName()+"数量="+f.getCount()+"腿的数量="+f.getLegs());
    		
    		Tiger t=new Tiger();
    		t.setName("老虎");
    		t.setCount(20);
    		t.setLegs(80);
    		System.out.println("动物的类型是:"+t.getName()+"数量="+t.getCount()+"腿的数量="+t.getLegs());
    	}
    
    }
    

      

  • 相关阅读:
    把指定文本输出到图片
    Delphi-WebService(53)
    YxdJSON
    Android 反编译工具
    delphi如何让程序最小化到任务栏(使用Shell_NotifyIcon API函数)
    守护进程-----杀死自己的进程再重新启动自己
    Delphi XE5通过DataSnap实现数据库三层应用
    用逆向设计和回归算法估算PWM
    早起的人生,到底有多赚
    为什么孝顺的人都会发家致富!我来告诉你!
  • 原文地址:https://www.cnblogs.com/liuyanzeng/p/5897569.html
Copyright © 2011-2022 走看看