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

Static Method

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


Static method can not be overridden... Please some one tell me the reason why static method can not be overridden in subclass? I have lot of confusion in Static Method. I kmow they are the class methods but i am getting confuse at so many times... Please some one help...


Thanks....
 
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 Gaurav,

static methods are known as class methods, overriding a method provides you run time polymorphism that is method selection at the run time on behalf of what object a reference variable is referring to. Static method are chosen at compile time on behalf of the reference variable. overriding never applies to static method because there is nothing like late binding or run time method selection.


Output:
Animal eat
Animal eat
Animal eat
Animal eat


One important fact:
There is difference between overriding and redefining a method. What we did in the Animal Dog example was redefining eat() method in the subclass Dog.
Overriding means, opening scope for run time polymorphism whereas redefining means just simply hiding the parent class method definition.
Hope this helps!


With Regards,
cmbhatt
[ April 07, 2007: Message edited by: Chandra Bhatt ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic