Download the JDK
Search the Tutorials
Hide the TOC
Trail: Learning the Java Language
Lesson: Interfaces and Inheritance
Section: Inheritance
Interfaces and Inheritance
Interfaces
Defining an Interface
Implementing an Interface
Using an Interface as a Type
Rewriting Interfaces
Summary of Interfaces
Questions and Exercises
Inheritance
Overriding and Hiding Methods
Hiding Fields
Using the Keyword super
Object as a Superclass
Writing Final Classes and Methods
Abstract Methods and Classes
Summary of Inheritance
Questions and Exercises
Home Page > Learning the Java Language > Interfaces and Inheritance
« Previous • Trail • Next »
Hiding Fields

> Within a class, a field that has the same name as a field in the superclass hides the superclass's field, even if their types are different. Within the subclass, the field in the superclass cannot be referenced by its simple name. Instead, the field must be accessed through `super`, which is covered in the next section. Generally speaking, we don't recommend hiding fields as it makes code difficult to read.

« Previous • Trail • Next »
Previous page: Overriding and Hiding Methods
Next page: Using the Keyword super