• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Overriding Vs Redefinition

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am quite confused with redefinition. In KB book it mentioned that overrriding is different from Redefinition.

Any example with explanation would greatly appreciated..
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we use covariant returns when re-defining?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks chan, now I got clear picture
 
This tiny ad will self destruct in five seconds.
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic