When the doStuff is called inside the loop it prints a whereas when it is outside the loop it prints d! And both the instances that invoke the method are a Dog annonymous Object.. Why is that..
Question 2:What does really redifinition of static method mean? When it has a different body in the subclass than wont that be invoked on runtime? What is the use of different body implementation of the static method in subclass and no use of it? I cant understand this concept..
Also I have made some changes to the code in the book.. In the book the methods in the superclass is static void doStuff() and in the subclass is static void dostuff(). So there is no question of redefiniton when both the methods are of different names. Is that an error in the book??
Any descriptive answers would be appreciated.. Thanks !!
Overriding(or Hiding) rules: 1) Static members (methods and variables) invoked based on the type of Object reference, no matter of class instance 2) Same rule apply for non static variables 3) Non static methods invoked based on instance of the class not by the type of object reference
For any static or non static member overriding(or hiding), purpose is same: override(or hide) and make use of the one that is required at runtime