Member Variables In Subclass Inherit?

Member Variables In Subclass Inherit?

Rule:
A subclass inherits all of the member variables within its superclass that are accessible to that subclass (unless the member variable is hidden by the subclass).

That is, subclasses
1. inherit those member variables declared as public or protected

2. inherit those member variables declared with no access specifier as long as the subclass is in the same package as the superclass. These variables are sometimes known as “friendly”.

3. don’t inherit a superclass’s member variable if the subclass declares a member variable using the same name. The subclass’s member variable is said to hide the member variable in the superclass.

4. don’t inherit private member variables

Scroll to Top