Class and Object Basics (1)

Source: Internet
Author: User

(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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.