Object-oriented-standard mobile phone class code and its test

Source: Internet
Author: User

1 /*2 Job: Please write the phone class as a standard class and then create the object test function. 3     4 mobile phone class:5 member variables:6 Brand: String brand;7 Price: int prices;8 color: String color;9 member Methods:Ten A corresponding getxxx ()/setxxx () method is given for each member variable.  One Final definition test: A creates an object that outputs the value of a member variable first through the GetXXX () method. The result of this time is: null---0---null - The member variable is then assigned a value through the Setxxx () method. Output the result again. This time the result is: Samsung---2999---local tyrants gold - */ the classPhone { -     //Brand -     PrivateString brand; -     //Price +     Private intPrice ; -     //Color +     PrivateString color; A      at     //getXxx () and Setxxx () methods -      PublicString Getbrand () { -         returnbrand; -     } -      -      Public voidSetbrand (String brand) { in          This. Brand =brand; -     } to      +      Public intGetPrice () { -         returnPrice ; the     } *      $      Public voidSetprice (intPrice ) {Panax Notoginseng          This. Price =Price ; -     } the      +      PublicString GetColor () { A         returncolor; the     } +      -      Public voidsetcolor (String color) { $          This. color =color; $     } - } -  the classPhonetest { -      Public Static voidMain (string[] args) {Wuyi         //Create a Phone object thePhone p =NewPhone (); -          Wu         //Direct output Default value -System.out.println (P.getbrand () + "---" +p.getprice () + "---" +P.getcolor ()); About          $         //Assigning a value to a member variable -P.setbrand ("Samsung"); -P.setprice (2999); -P.setcolor ("Local Tyrants Gold"); A         //Output Again +System.out.println (P.getbrand () + "---" +p.getprice () + "---" +P.getcolor ()); the     } -}

Object-oriented-standard mobile phone class code and its test

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.