This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What is the difference between overriding a method and redefining a method ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is the difference between overriding a method and redefining a method ?" Watch "What is the difference between overriding a method and redefining a method ?" New topic
Author

What is the difference between overriding a method and redefining a method ?

Vijay Tyagi
Ranch Hand

Joined: Feb 15, 2010
Posts: 52
static methods cannot be over ridden
But why is it that they can be overridden when downcasting is used ?

Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Not quite sure what you mean by downcasting? can you elaborate.

Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Vaibhav Mittal
Greenhorn

Joined: Jun 11, 2008
Posts: 23
Since static methods are class members and not instance members, the method that is corresponding to the type of the type of the reference variable will be called.

In your example,


is equivalent to converting the object of class Animal to object of class Dog and then calling the method on it. This works because the class that the compiler sees is Dog class and hence invoke the method corresponding to Dog class.

In the next case, since a[] is an array that holds Animal objects, the method corresponding to Animal class is invoked.

I hope it clears your doubt.

"Life is good"
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Try writing an SSCCE which demonstrates your question, then see what happens when you run it. You will remember so much more of what you do than of what you are told.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is the difference between overriding a method and redefining a method ?
 
Similar Threads
static methods
static methods
Static Doubt
a question
override and redifinition?