Why static methods cannot be overridden?

1 answer(s)
Answer # 1 #

Simple reason is there. Static methods belong to the class. Not to the object. But overriding is an object thing, no? For overriding, the program decides at runtime which method to call. It depends on the actual object.

With static methods, there is no object involved. The compiler already knows the method to call using the class name. It is called early binding. Because it is linked to class, not object, it cannot be overridden. If you write same static method in child class, it is method hiding, not overriding.

[26 Day]