As per your suggestion, I am including the question also. The code given below is with refernce to the explanation of the fact that "static methods can not be overridden". However, we are always free to redefine the method as done in the following code. Now I again repeat my question : What is the difference between overriding and redefining a method. From the code it seems as if we are doing overriding. Please elaborate method overriding & redefining.
Please note that the code given below works pretty fine and produces an output "aaa" when run.
I think you are agree with me with output. If yes, then observed one thing here... when a is a object of new Dog then "d" should print. But we are getting 'a' in the output. This means that polymorphism or we can say overriden is not there. This is simply redifining.
We can not override static methods, we can only redefine them.
Overriding a method means you are giving a new meaning for the method in your derived class for an already existing method in the base class. When you are overriding, you must strictlyfollow all rules of overriding.
If you dont follow the rules of overriding, you will no longer be overriding the method, you are defining an all new method!!!
Joined: Feb 03, 2007
I could not follow anybody's explanation. Anybody else... Can anyone explain the difference between overriding and redefining a method with an illustrative example(s)? Will moderators please help me out!!!