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.
CodePudding user response:
No need to wonder. We have a rather comprehensive language specification at our disposal.
In particular
A class
C
inherits from its direct superclass typeD
all concrete methodsm
(both static and instance) for which all of the following are true:
m
is a member ofD
.m
is public, protected, or declared with package access in the same package asC
.- No method declared in
C
has a signature that is a subsignature (§8.4.2) of the signature ofm
as a member ofD
.
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.