1 /*2 Standard Code3 4 Student class:5 member variable: name,age6 Construction Method: No parameter, with two parameters7 member Method: GetXxx ()/setxxx (), show8 9 assign a value to a member variable:Ten ①setxxx () high flexibility One ② construction method. A - output member Variable value: - ①getxxx () high flexibility the ② by calling the show () method. - */ - - classstudent{ + PrivateString name; - Private intAge ; + A PublicStudent () { at - } - - PublicStudent (String name,intAge ) { - This. Name =name; - This. Age =Age ; in - } to + PublicString GetName () { - returnname; the } * $ Public intGetage () {Panax Notoginseng returnAge ; - } the + Public voidsetName (String name) { A This. Name =name; the } + - Public voidSetage (intAge ) { $ This. Age =Age ; $ } - - Public voidShow () { theSystem.out.println (name+ "----" +Age ); - }Wuyi } the - classstudenttest2{ Wu Public Static voidMain (string[] args) { - //non-parametric construction +setxxx①+① AboutStudent S1 =NewStudent (); $S1.setname ("Little Lazy"); -S1.setage (99); -System.out.println (S1.getname () + "---" +s1.getage ()); - //①+② A s1.show (); + the //construction method gives value ②+① -Student s2 =NewStudent ("Small Leather", 99); $System.out.println (S2.getname () + "---" +s2.getage ()); the //②+② the s2.show (); the } the}
C-4 a standard student class code and test