Hi all, I just have a question about static methods. May a subclass override a static method from its superclass and declare it as non-static method? or vice-versa? I've tried it and it would not allow me to do it. I am having some doubts because I thought I've done a mock exam question that had asked me this and the answer (I thought) was that it was indeed possible. Please correct me if I am wrong. Thanks.
Static methods belong to the class, and thus don't need an instance object to allow them to be called. When you call a static method you need to specify the following syntax indicating the class: class.staticMethod() Overridding a method has to do with polymorphic functions, which is a nice way of saying dynamic (runtime) binding that occurs based on the referenced type. Back to static methods... Since you have to call a static method knowing ahead of time the class involved, class_name.method_name() what you're actually doing at the coding level is called static binding which takes place at compile time and not runtime. So you can't have polymorphism, which means you can't override using static binding Just another reason it doesn't make too much sense to be able to override static class methods.
<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes