java學(xué)生類 java定義一個動物類,用構(gòu)造方法實現(xiàn)動物的實例化?
java定義一個動物類,用構(gòu)造方法實現(xiàn)動物的實例化?public class Animal{ int height//身高 int weight//體重 int age//年齡 Str
java定義一個動物類,用構(gòu)造方法實現(xiàn)動物的實例化?
public class Animal{ int height//身高 int weight//體重 int age//年齡 String sex//性別 public Animal(int height,int weight,int age,String sex){//帶4個參數(shù)的構(gòu)造方法 this.height = height this.weight= weight this.age= age this.sex= sex}public static void main(String[] args) { Animal animal = new Animal(100,60,2,"雄性")/*animal這個對象就具有height、weight、age、sex屬性值了*/}}