Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What components of the superclass do the subclasses inherit?

Do all of the subclasses of a superclass inherit the superclass’ instance variables, constructors, mutators, and accessors?

Assuming that all members of the superclass is public.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No need to wonder. We have a rather comprehensive language specification at our disposal.

In particular

A class C inherits from its direct superclass type D all concrete methods m (both static and instance) for which all of the following are true:

  • m is a member of D.
  • m is public, protected, or declared with package access in the same package as C.
  • No method declared in C has a signature that is a subsignature (§8.4.2) of the signature of m as a member of D.

Notice the highlighted first point. Because when talking about constructors the spec says

Constructor declarations are not members. They are never inherited and therefore are not subject to hiding or overriding.

Which, back to your question, means that public instance variables and methods (accessors and mutators are not a Java language construct, they’re just methods) are inherited. Constructors are not.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading