Higgledy Smith wrote:I remember things better if I understand the underlying reason for the behavior. That said, can anyone explain why static methods cannot be overridden?
Thanks.
Static methods can be hidden (but not overridden.) Why can't they be overridden? Because overriding uses
polymorphism (which calls the correct method based on the actual type of the instance referred to by the reference.) But with static methods you have no underlying instance, since they are linked to the class as a whole. That's why you can't override a static method (but if you declare a static method with the same signature in a subclass, that static method will hide the superclass' static method in subclass code.)