Hi all , I have read several posts about static method confusion which says "static method are not inherited and also they can't be overridden "
but still I have doubt
Here is the coding for my question
As in the comment statement Uncommenting the first method(which has Integer as return type )and commenting the second method makes compilation success but in reverse I got this error.
Since static methods are not inherited 1. why the compiler let us do that ? 2. It also accepts the subtype of superclass static method return method (which is one of the rule for overriding -in my case Integer is-a Number )
So,what I understood is, even though static methods are not inherited and can't be overridden we must adhere to overriding rules while using static methods . Am I correct or misunderstood ?
when we create a static method inside a sub class with the same heading as in a super class, it won't be consider as the overrided method. It will treat as a separate method.
And the call to the static methodwill depends on the refernce only. not on the object, which is used for calling the method. So, eventhough the supar class refernce hold a subclass object and calling a static method, the superclass method will be called.
Hi Parthiban, as per your question I am trying to answer that when you try to override a static method ,it's seems that it is following overriden rules.But when the the time comes you try to use it then it checks the refference type not object type. So actually rules for overriden are same only this(object type).And the method are not actually overriden.
Joined: Apr 15, 2008
Hi all, Thanks for your replies.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Please clarify my doubts about static methods