Java Object-oriented exercises

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 (printname), display weapon (printweapon)
(2) Create two objects in the main method of the Master class: Zhubajie,sunwukong. and separately for his
The two attributes (Name,weapon) are assigned, and finally the Printname is called, Printweapon method
Displays the property values for two objects.


package Com.hanqi; Public class Xiyoujirenwu { double height; String name; String weapon; void Printname () { System.out.println ("This is" +name); } void Printweapon () { System.out.println (name+ "weapon is" +weapon "); } }
 Public Static voidMain (string[] args) {//TODO Auto-generated method stubsXiyoujirenwu XiYouJiRenWu1=NewXiyoujirenwu (); Xiyoujirenwu1.name= "Monkey King"; Xiyoujirenwu1.weapon= "Ruyi Golden cudgel";        Xiyoujirenwu1.printname ();        Xiyoujirenwu1.printweapon (); Xiyoujirenwu XIYOUJIRENWU2=NewXiyoujirenwu (); Xiyoujirenwu2.name= "Pig"; Xiyoujirenwu2.weapon= "Nine Teeth Rake";        Xiyoujirenwu2.printname ();    Xiyoujirenwu2.printweapon (); }

Java Object-oriented exercises

Related Article

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.