Java Section 34th inheritance relationship

Source: Internet
Author: User

2016-06-29

Java only supports a single inheritance relationship.

 Packagecom.java1995;/*** Parent class: Human *@authorAdministrator **/ Public classpeople {/*** Package*/    PrivateString name; Private intAge ; /*** Implementation of the package*/     Public voideat () {System.out.println ("People are eating."); }         PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     Public intGetage () {returnAge ; }     Public voidSetage (intAge ) {         This. Age =Age ; }    }

 Packagecom.java1995;/*** Class Two sub-category: Chinese *@authorAdministrator **/ Public classChineseextendspeople{/*** Inheritance*/     PublicChinese () {Super(); }    /*** Sub-class method*/     Public voidSpeakchinese () {System.out.println ("Chinese People speak Chinese"); }}

 Package com.java1995; /**  @author*/Publicclassextends  chinese{     /**     * Sub-class     method * /Public     void  Speakhebeilang () {        System.out.println ("Hebei people speak Hebei dialect");}    }

 Package com.java1995; /**  @author*/Publicclass  Test    {public  staticvoid  main (string[] args) {        hebeipeople h=new  Hebeipeople ();        H.speakhebeilang ();    }}

Resources

[1] Java Easy Start Classic tutorial "full version"

Java Section 34th 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.