java-Basic Package

Source: Internet
Author: User

 PackageTest.studet_manager; Public classStudent {Static intnum = 100; //numbered--Unique    Private  intNumber =-1; //name    PrivateString name = ""; //Sex    PrivateString sex = ""; //Age    Private intAge =-1; //class    PrivateString grade = ""; //Achievements    Private intScore =-1; /** methods for set and get*/     Public voidsetsex (String sex) { This. Sex =sex; }         PublicString Getsex () {returnsex; }         Public voidsetName (String name) { This. Name =name; }         PublicString GetName () {returnname; }         Public voidSetage (intAge ) {        //age must be greater than 0        if(age>=0) {             This. Age =Age ; }            }         Public intGetage () {returnAge ; }         Public voidSetgrade (String grade) { This. grade =grade; }         PublicString Getgrade () {returngrade; }         Public voidSetScore (intscore) {        if(Score >= 0) {             This. score =score; }            }         Public intGetscore () {returnscore; }         Public voidSetnumber (intNumber ) {         This. Number = This. number+0; }     Public intGetNumber () {returnNumber ; }         PublicStudent () {//TODO auto-generated Constructor stub++num;  This. Number =num; }     PublicStudent (intnumber,string name,string Sex,intAge,string grade,intscore)        {GetNumber ();        GetName ();        Getsex ();        Getage ();        Getgrade ();    Getscore (); } @Override PublicString toString () {//TODO auto-generated Method Stub        return""+ This. number+ "" + This. name+ "" + This. sex+ "" + This. age+ "" + This. grade+ "" + This. score+ "\ n"; } @Override Public Booleanequals (Object obj) {//TODO auto-generated Method Stub//determines whether the object to compare is not NULL        if(obj = =NULL) {            return false; }        //judging the object to compare is not itself        if(obj = = This) {            return true; }        //determine if the object to compare is not the same type        if(objinstanceofStudent) {Student Student=(Student) obj; returnstudent.number== This. number&&student.name== This. name&&student.sex== This. sex&&student.age== This. age&&student.grade== This. grade&&student.score== This. Score; }        return false; } @Override//Note: The Hashcode method must be consistent with the attributes in the Equals method     Public inthashcode () {//TODO auto-generated Method Stub        return  This. number- This. Name.hashcode ()- This. Sex.hashcode ()- This. age- This. Grade.hashcode (); }    //write some of your own ways     Public voidLearn () {System.out.println ( This. name+ "Learning computer language"); }}

java-Basic Package

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.