String Name; double Height; //属性 String Weapon; void printName() //方法 { System.out.println("人物名称:"+Name); } void printWeapon() { System.out.println("使用的武器是:"+Weapon); }
XiYouJiRenWu RenWu1=new XiYouJiRenWu(); RenWu1.Name="孙悟空"; RenWu1.Weapon="如意金箍棒"; RenWu1.Height=2.0; RenWu1.printName(); RenWu1.printWeapon(); XiYouJiRenWu RenWu2=new XiYouJiRenWu(); RenWu2.Name="猪八戒"; RenWu2.Weapon="九齿钉耙"; RenWu2.Height=1.88; RenWu2.printName(); RenWu2.printWeapon();
运行结果