Important Points for inheritance in Java

Source: Internet
Author: User

1.Private members of superclass is not directly accessible to subclass. As in this example, Animal variable nooflegs isn't accessible to Cat class but it can indirectly accessible via getter and setter methods.
2.Superclass members with the default access is accessible to subclass only if they be in the same package.
3.Superclass constructors is not inherited by subclass.
4.If superclass doesn ' t has default constructor, then subclass also needs to has an explicit constructor defined. Else It'll throw compile time exception.
5.Java doesn ' t support multiple inheritance, a subclass can extends only one class. So here Animal are implicitly extending Object class and Cat is extending Animal class but due to Java inheritance Transiti ve nature, Cat class also extends Object class.

Excerpt from: Http://www.journaldev.com/644/inheritance-in-java-example

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Important Points for inheritance in Java

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.