This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have a doubt .....thats bothering me a lot... Can static methods be overridden?? atleast by static methods..or they cannot be overridden by any method??
Please give me the right explanation..as i am finding 2 different views about this question.
Thanks in advance...
S Javainn
Javainn<br /> <br />SCJP,SCWCD,SCBCD,<br />ICED (IBM-287,IBM-484,IBM-486)
IBM certified in DB2 V 8.1 Family Fundamentals (IBM 700)
Tony Morris
Ranch Hand
Joined: Sep 24, 2003
Posts: 1608
posted
0
static methods cannot be overridden. Suggestions to the contrary should be sent to /dev/null and ignored.
Thankyou for the confirmation... I just want to know the difference between overridden methods and hidden methods as in one book..Khalid Mughal ,they say that static methods can be hidden...
Thanks in advance..
Alton Hernandez
Ranch Hand
Joined: May 30, 2003
Posts: 443
posted
0
Originally posted by S javainn: Hi Tony,
Thankyou for the confirmation... I just want to know the difference between overridden methods and hidden methods as in one book..Khalid Mughal ,they say that static methods can be hidden...
Thanks in advance..
Some terminologies that you may be interested in, with their simple definitions:
Overloading - defining a method of the same name but with different signatures.
Overriding - ability to replace the superclass method with the subclass own method
Hiding - preventing a member from being inherited due to a declaration in the subclass.
Shadowing - when a method or variable cannot be refered to using a simple name because of an existence of a method or variable of the same name in the current scope. [ February 27, 2005: Message edited by: Alton Hernandez ]
Srinivasa Raghavan
Ranch Hand
Joined: Sep 28, 2004
Posts: 1228
posted
0
Here is the Good Example from Animesh. [ February 27, 2005: Message edited by: Srinivasa Raghavan ]
The important difference between overriding instance methods and hiding static methods is: -for overridden methods, the choice of which method to call is made at execution time based on the actual type of the object referred to by the reference on which the method was called -for hidden methods, the choice of which method to call is made at compile time based only on the type of the reference on which the method is called
The rules on no narrowing access modifiers, no new throws clauses, same return types, matching static vs. nonstatic, all apply to both method overriding and method hiding.