編寫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刪除。



猜您在找 2.定義圖形類Shape,該類中有獲得面積的方法getArea();定義長方形類Rect,該類是Shape的子類,類中有矩形長和寬的變量double a,double b,設置長和寬的方法setWidth()、setHeight(),使用getArea()求矩形面積;利用getArea方法實現題1中圓面積的求解。 編寫一個Java應用程序,該程序包括3個類:Monkey類、People類和主類 E。要求: (1) Monkey類中有個構造方法:Monkey (String s),並且有個public void speak() 方法,在speak方法中輸出“咿咿呀呀......”的信息。 (2)People類是Monkey類的子類,在People類中重寫方法speak(),在speak方法 中輸出“小樣的,不 solr 查詢獲取數量getCount() Object類中有哪些方法 mysql count group by統計條數方法 錯誤: 在類中找不到 main 方法, 請將 main 方法定義為:public static void main(String[] args) Java基礎-接口.編寫2個接口:InterfaceA和InterfaceB;在接口InterfaceA中有個方法void printCapitalLetter();在接口InterfaceB中有個方法void printLowercaseLetter();然 后寫一個類Print實現接口InterfaceA和InterfaceB,要求 方法 實現輸出大寫英文字母表的功能,printLowerca laravel 查詢以某個字段為鍵名(可用於去重) mysql 統計數量可用count(1) 選擇模型 | 如何構建一個疾病的動物模型? | animal model of disease 錯誤: 在類中找不到 main 方法, 請將 main 方法定義為:public static void main(String[] args)否則 JavaFX 應用程序類必須擴展javafx.ap
 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM