Java Lab Project three--programming implementation of the person class, student class design and its inheritance relationship

Source: Internet
Author: User
Tags define abstract

Program:

Programming implementation of person class, student class design and its inheritance relationship

The code is as follows:

Define abstract class Person

1 /*2 * Description: Creating abstract Classes3  * 4 * Written By:cai5  * 6 * Date written:2017-10-177  * 8  * */9 Ten  One  Packageresource; A  -  Public Abstract classPerson { -      the     PrivateString name;//name -     Private intAge//Age -     PrivateString sex;//Sex -     PrivateString address;//Address +     PrivateString telephone;//Telephone -      +     //Defining construction Methods A      at      PublicPerson () {} -  -      PublicPerson (String name,intAge , String sex, string address, - String Telephone) { -          -          This. Name =name; in          This. Age =Age ; -          This. Sex =sex; to          This. Address =address; +          This. Telephone =Telephone; -     } the  *     //define Setter () and Getter () methods $     Panax Notoginseng      PublicString GetName () { -         returnname; the     } +  A      Public voidsetName (String name) { the          This. Name =name; +     } -  $      Public intGetage () { $         returnAge ; -     } -  the      Public voidSetage (intAge ) { -          This. Age =Age ;Wuyi     } the  -      PublicString Getsex () { Wu         returnsex; -     } About  $      Public voidsetsex (String sex) { -          This. Sex =sex; -     } -  A      PublicString getaddress () { +         returnaddress; the     } -  $      Public voidsetaddress (String address) { the          This. Address =address; the     } the  the      PublicString Gettelephone () { -         returnTelephone; in     } the  the      Public voidSettelephone (String telephone) { About          This. Telephone =Telephone; the     } the  the     //Overwrite ToString () method + @Override -      PublicString toString () { the         return"Person [name=] + name +", age= "+ Age +", sex= "+SexBayi+ ", address=" + address + ", telephone=" + telephone + "]"; the     } the      -     //use template mode, define simple templates, print information -     /* the * Template mode is one of the object-oriented design patterns, its approximate thought (personal understanding): the * Complete the identified content in an abstract method, while the indeterminate part is written as an abstract method and called the * and the concrete implementation of the abstract method, given to inherit his class to concrete realization, the * So developers can just write their own implementation parts and then in the main method, - * By invoking the template method directly from the instantiated abstract class, you can the      *  the * The following method is just a simple representation the      *  94      * */ the      Public voiddisplay () { the          theSystem.out.println ( This);//Public Part98System.out.println ("-------------------coquettish Java split Line-----------------"); AboutGetInfo ();//developer-specific implementations -System.out.println ("-------------------coquettish Java split Line-----------------");101SYSTEM.OUT.PRINTLN ("This output method uses template design mode, the above for student information!") " );//Public Part102     103     }104      the     //declaring abstract methods, printing the addition information of subclasses106      Public Abstract voidgetInfo ();107 108 109}

Defining student classes, inheriting abstract classes

1 /*2 * Description: Define student class, inherit person method3  * 4 * Written By:cai5  * 6 * Date written:2017-10-177  * 8  * */9 Ten  One  Packageresource; A  -  Public classStudentextendsPerson { -      the     PrivateString Sno;//School Number -     PrivateString ClassName;//class -      -     //Defining construction Methods +      PublicStudent (String name,intAge , String sex, string address, - String telephone,string sno,string className) { +          A         Super(name,age,sex,address,telephone); at          This. Sno =Sno; -          This. ClassName =ClassName; -     } -      -  -     //define Setter () and Getter () methods in      PublicString Getsno () { -         returnSno; to     } +  -      Public voidSetsno (String Sno) { the          This. Sno =Sno; *     } $ Panax Notoginseng      PublicString GetClassName () { -         returnClassName; the     } +  A      Public voidsetclassname (String className) { the          This. ClassName =ClassName; +     } -  $  $     //implementing the Parent class abstract method - @Override -      Public voidGetInfo () { the          -System.out.println ("School Number:" + This. Getsno () + "\ T class:" + This. GetClassName ());Wuyi     } the      -}

Java Lab Project three--programming implementation of the person class, student class design and its inheritance relationship

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.