• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is diff between method redefinition and mehtod overriding?

 
Arpit Gadle
Ranch Hand
Posts: 69
Linux MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21518
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Harvinder Thakur
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OverridingVsHiding
This link will help you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic