Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overridden doubt

 
trivikram Kumar
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static methods cannot be overridden.
Suggestions to the contrary should be sent to /dev/null and ignored.
 
trivikram Kumar
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the Good Example from Animesh.
[ February 27, 2005: Message edited by: Srinivasa Raghavan ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic