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