Spec-Zone .ru
спецификации, руководства, описания, API
Trail: Learning the Java Language
Lesson: Interfaces and Inheritance
Section: Inheritance
Hiding Fields
Home Page > Learning the Java Language > Interfaces and Inheritance

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.


Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: Polymorphism
Next page: Using the Keyword super