*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding Vs Redefinition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding Vs Redefinition" Watch "Overriding Vs Redefinition" New topic
Author

Overriding Vs Redefinition

Sathya Shanmugam
Ranch Hand

Joined: Mar 02, 2007
Posts: 45
I am quite confused with redefinition. In KB book it mentioned that overrriding is different from Redefinition.

Any example with explanation would greatly appreciated..
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
I am quite confused with redefinition. In KB book it mentioned that overrriding is different from Redefinition.


When you override a method you open the door of having polymorphic behavior.
That is calling subclass version of the method using parent class reference.

So far redefing is concerned, there is nothing like polymorphism. Redefining takes place in case of static methods because static methods can't be overridden (they are class specific things).

Look at the following example:



You can see easily, while redefining a method is different, it simply hides the parent class method. While overriding a method gives you avail run time method invocation decision on behalf of what type of object your reference variable is holding instead of the type of reference variable(that is taking place when calling static methods).

Hope you got the concept!

Thanks and Regards,
cmbhatt


cmbhatt
megha joshi
Ranch Hand

Joined: Feb 20, 2007
Posts: 206
Can we use covariant returns when re-defining?
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Originally posted by Megha Joshi

Can we use covariant returns when re-defining?


Hi Megha,

While redefining a method, you can change the method return type. The actual meaning of covariant return is availed when we override a method so that run time polymorphism is assured.

Look at the code example below:



You may comprehend this!

Thanks and Regards,
cmbhatt
Sathya Shanmugam
Ranch Hand

Joined: Mar 02, 2007
Posts: 45
thanks chan, now I got clear picture
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Overriding Vs Redefinition