編寫Java應用程序,定義Animal類,此類中有動物的屬性:名稱 name,腿的數量legs,統計動物的數量 count;方法:設置動物腿數量的方法 void setLegs(),獲得腿數量的方法 getLegs(),設置動物名稱的方法 setKind(),獲得動物名稱的方法 getKind(),獲得動物數量的方法 getCount()。定義Fish類,是Animal類的子類,統計魚的數量 co


package com.hanqi.test;

public class Animal {
    private String name;
    private int legs;
    private int count;
    public String getKind() {
        return name;
    }
    public void setKind(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 com.hanqi.test;

public class Fish extends Animal {
    

}
package com.hanqi.test;

public class Tiger extends Animal {

}
package com.hanqi.test;

public class SouthEastTiger extends Tiger {

}
package com.hanqi.test;

public class Test02 {

    public static void main(String[] args) {
        Rect re=new Rect();
        re.setA(20);
        re.setB(30);
        re.getArea();
        
        Circle cc=new Circle(30);
        
        System.out.println("radius=30圓 的面積是:"+cc.getArea());
        
        SouthEastTiger set= new SouthEastTiger();
        set.setCount(20);
        System.out.println("SouthEastTiger的數量是:"+set.getCount());
        Tiger t=new Tiger();
        t.setCount(15);
        System.out.println("tiger的數量是:"+t.getCount());

    }

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM