(1) Writing the journey to the People class (xiyoujirenwu)
The attributes are: height (height), name, weapon (weapon)
methods are: Display Name () , explicit Printname Display weapons ( printweapon)
(2) Create two objectsin the main method of the master Class :Zhubajie,sunwukong. and separately for his
the two attributes (name,weapon) areassigned, and finally the Printname is called, Printweapon method
Displays the property values for two objects.
(1)
Package Shiba; Public class xiyou { int height; String name; String Wuqi; String printname () { return name; } String Printwuqi () { return Wuqi; } }
(2)
Package Shiba; Public classXIYOU1 { Public Static voidMain (string[] args) {//TODO Auto-generated method stubsXiyou suwukong=Newxiyou (); Xiyou Zhubajie=Newxiyou (); Suwukong.name="Monkey King"; Suwukong.height=178; Suwukong.wuqi="Ruyi Golden Cudgel"; Zhubajie.height=177; Zhubajie.name="Pig"; Zhubajie.wuqi="Nine Teeth rake"; System. out. println (suwukong.name+":"+Suwukong.wuqi); System. out. println (zhubajie.name+":"+Zhubajie.wuqi); }}
Class and Object Basics (1)