aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overridden doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overridden doubt" Watch "Overridden doubt" New topic
Author

Overridden doubt

trivikram Kumar
Ranch Hand

Joined: Feb 21, 2005
Posts: 172
Hi Pals,

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
static methods cannot be overridden.
Suggestions to the contrary should be sent to /dev/null and ignored.


Tony Morris
Java Q&A (FAQ, Trivia)
trivikram Kumar
Ranch Hand

Joined: Feb 21, 2005
Posts: 172
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..
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
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
Here is the Good Example from Animesh.
[ February 27, 2005: Message edited by: Srinivasa Raghavan ]

Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
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.


Mike Gershman
SCJP 1.4, SCWCD in process
 
 
subject: Overridden doubt