Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

difference between redefinition and overriding

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want the difference between method redefinition and method overriding. Can som1 please explain with an example..
 
Ranch Hand
Posts: 137
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ansuman,

Overidding is very specific to the context of Redifining which is a general phenomena.In java redifining can refer to Overloading or Overriding.In both cases we redifine a method but achieve different different purposes.Overidding is more than redifining,if we stress on OOPS.
It relates to dynamic polymorphism or dynamic dispatch or Early/Late/Static/Dynamic Bindings.Redifinition serves no objective in OOPS,its just a general perspective to the understanding of a particular construct.
 
ansuman mohapatra
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks 4 writin in...

but the doubt I have is in static methods overriding is not allowed, rather they allow method redifinition !!...That I didnt understand.

If method redefining refers to overloading or overriding then whats the difference of "Static Methods can't be overriden but can be redefined".
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this discussion may help.

I think I saw something similar discussed in ht e FAQ section will provide the link if i can find it.

HTH
Shikhar
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That means the static methods can't be called in the context of overriding as overriding generally done with the specific version of method being invoked based on the *actual object* created at runtime.

As such the static methods are bound to the class and NOT the instances, this does not qualify for the aforementioned rule. That's why they say the static methods are NOT overridden but redefined.

You can try with a small example program for the same.
[ July 11, 2008: Message edited by: Raghavan Muthu ]
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sidharth Pallai
Ranch Hand
Posts: 137
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ansuman mohapatra:
hey thanks 4 writin in...

but the doubt I have is in static methods overriding is not allowed, rather they allow method redifinition !!...That I didnt understand.

If method redefining refers to overloading or overriding then whats the difference of "Static Methods can't be overriden but can be redefined".



Its very basic to say "Static Methods can't be overriden but can be redefined". I would say that "Static method can be overidden !!,but they cant be overriden to be non-static" ie Static methods doesn't adhere to Dynamic Polymorphism or Dispatch.
Take this example :


If a.meth1() calls Super class method then i dont think static method respond to dynamic dispatch calls, unlike a.meth2() which does.

Apart form saying redifining static method i would consider saying it as Hidding Static methods, because static methods are hidden not overriden.
In this case Hidding/Redifining differs a lot with Overriding.
 
reply
    Bookmark Topic Watch Topic
  • New Topic