java學(xué)生類 java定義一個(gè)動(dòng)物類,用構(gòu)造方法實(shí)現(xiàn)動(dòng)物的實(shí)例化?
java定義一個(gè)動(dòng)物類,用構(gòu)造方法實(shí)現(xiàn)動(dòng)物的實(shí)例化?public class Animal{ int height//身高 int weight//體重 int age//年齡 Str
java定義一個(gè)動(dòng)物類,用構(gòu)造方法實(shí)現(xiàn)動(dòng)物的實(shí)例化?
public class Animal{ int height//身高 int weight//體重 int age//年齡 String sex//性別 public Animal(int height,int weight,int age,String sex){//帶4個(gè)參數(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這個(gè)對(duì)象就具有height、weight、age、sex屬性值了*/}}