Java Reference
In-Depth Information
Let's review the key concepts behind
super( )
. When a subclass calls
super( )
, it is call-
ing the constructor of its immediate superclass. Thus,
super( )
always refers to the super-
class immediately above the calling class. This is true even in a multilevel hierarchy. Also,
super( )
must always be the first statement executed inside a subclass constructor.
Using super to Access Superclass Members
There is a second form of
super
that acts somewhat like
this
, except that it always refers
to the superclass of the subclass in which it is used. This usage has the following general
form:
super.
member
Here,
member
can be either a method or an instance variable.
This form of
super
is most applicable to situations in which member names of a subclass
hide members by the same name in the superclass. Consider this simple class hierarchy: