Instance method overriding
Since, as we have seen in the previous section, class (or static) members cannot override each other but only hide, we can talk about overriding instance members, only. We have also already established that instance fields hide each other and the rules of field hiding are quite different from the much simpler rules of method overriding, so the best practice would be to not expose instance fields and access their values via getters and setters only. This way, instance member overriding is reduced to instance method overriding, and that is what we are going to describe in this section.
The rules for instance method overriding are not different than the rules for interface default method overriding: a method in a child ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access