Hiding, in the technical sense defined in this specification, applies only to members which would otherwise be inherited but are not because of a declaration in a subclass.
Nil. Hatamova wrote: But when i see both of these code without any explanation i dont now which one is overriding and which one is riding
Joe Bishara wrote:The key is to look at the method’s modifier. An overridable method is one that is not declared as private, static or final.
Roel De Nijs wrote:in order for a non-final method to be overridden or hidden, it must be visible to the subclass
Joe Bishara wrote:An overridable method is one that is not declared as private, static or final.
Roel De Nijs wrote:A subclass in a different package can hide a method with package-private access of the superclass, but not override it.
Joe Bishara wrote:
Joe Bishara wrote:An overridable method is one that is not declared as private, static or final.
This statement implies that a method can be overridden if it is not declared as private, static or final.
Joe Bishara wrote:Based on your original statement "in order for a method to be overridden or hidden, it must be visible to the subclass", in your code, the makeSound() method in the Lion class does not override or hide the makeSound() in the Animal class because it is not visible.