• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Overriden Vs Re-Define

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had read static methods cannot be overriden but can be re-defined.

Can you please tell me the difference between overriding and Re-defineing. Thanks Siva
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Siva,

overriding applies to inheritance.
It means that you have the exact same notation of a method, or a covariant return type of a method, but with different body.


The covariant return means, that the overriding class can return anything that is a subclass of the original (in class Animal it is "Object") return type. Since "String" is a subclass of "Object", we are fine.

Static methods can NOT be overwritten, because they are class methods. Only instance methods can be overwritten.
 
siva prasaad
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tommaso Nuccio for your response.

I agree with you in case of overiden concept.

But i want to know what is the difference between overriden and re-define
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Prasad,


Prasad says:
But i want to know what is the difference between overriden and re-define



In one line,
Overriding means polymorphism can be availed.
Redefining means no polymorphism.

Polymorphism means, being able to bind subclass methog at run time
using the base class reference variable.
Animal ani = new Dog();
ani.eat(); //at run time Dog's eat will be selected. (if dog overrides it) This is called polymorphism.

Redefining, you can understand in case of static method. methods will be selected on behalf of what is the type of reference type instead of what object it is referring to.

Regards,
cmbhatt
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

redifining can be done
1) with statics
2) with private

Example for the latter:


Also with redifining private methods you won't see polymorphy, but here only because it just doesn't compile that way.

Yours,
Bu.
[ April 16, 2007: Message edited by: Burkhard Hassel ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic