Category Archives: Overriding Default Methods

Hiding Fields A subclass cannot override inherited fields of the superclass, but it can hide them. The subclass can define fields with the same name as in the superclass. If this is the case, the fields in the superclass cannot be accessed in the subclass by their simple names; therefore, they are not inherited by the subclass. A hidden static field can always be accessed by using the superclass name in the subclass declaration. Additionally, the keyword super can be used in non-static code in the subclass declaration to access hidden static fields. The following distinction between invoking instance methods on an object and accessing fields of an object must be noted. When an instance method is invoked on an object using a reference, it is the dynamic type of the reference (i.e., the type of the current object denoted by the reference at runtime), not the declared type of…

Read more

11/11