Questions about the following: (from SCJP 6 Study Guide by Kathy Sierra and Bert Bates. Chapter 2: Statics)
Output: a a a
Why? On second thought, I guess I knew the answer, it's because the polymorphic method invocations where the method of the instance of the object (not the reference variable) is invoked only applies to instance methods (not static). If I'm right, my question would be, how what is that redefinition does?
static methods are not overridden. in your case static method of superclass is hidden by static method of the same name. you are right - there is no dynamic method dispatch that happens during overrding whereby the method is invoked on the instance of the object at the other end of reference. static methods are class methods - they are not tied to any instance/object. you can invoke class methods on the reference variables although it is not recommended. taking your example when you do
Animal a = new Animal();
a.doStuff(); // it actually transforms into Animal.doStuff()\