File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What is diff between method redefinition and mehtod overriding? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What is diff between method redefinition and mehtod overriding?" Watch "What is diff between method redefinition and mehtod overriding?" New topic
Author

What is diff between method redefinition and mehtod overriding?

Arpit Gadle
Ranch Hand

Joined: Dec 16, 2008
Posts: 69

We cannot override a static method but we can redefine it. But looking at the code below it seems that we are overriding a static method? So wat is the diff between method redefinition and method overriding?




[HENRY: Added Code Tags]
[ December 16, 2008: Message edited by: Henry Wong ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18962
    
  40



You code example is actually a good demo of this. Notice that it is calling the Animal class' method, even for the Dog class. The reason is... the reference (array element) is an animal, hence, it calls the animal method. If the method had been overriden, then the Dog object would have called the Dog's version of the method (overridden method) instead.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Harvinder Thakur
Ranch Hand

Joined: Jun 10, 2008
Posts: 231
OverridingVsHiding
This link will help you.


thanks
Harvinder
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is diff between method redefinition and mehtod overriding?