C-4 a standard student class code and test

Source: Internet
Author: User

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

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.