+ 1

What is the difference between shadowing and overriding in java??

both looks similar to me. Can anyone make me clear.

17th Oct 2018, 6:52 PM
Sandeep Kumar Suthar
2 Antworten
+ 1
Instance methods can be overridden, static methods can not be overridden only hidden. They are similar, but the instance based doesn't care which class (parent or child) the instance is stored as only how it was created. To reference the child static, you must explictly specify the child class.
17th Oct 2018, 9:45 PM
John Wells
John Wells - avatar
+ 1
that means if a method is static, then we cant override it in the sub class. if we create a object of the subclass and invoke the static method. then, it will give call method from the parent class as the method in sub class is just a shadow of method in parent class.
18th Oct 2018, 2:50 AM
Sandeep Kumar Suthar