• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

overriding static/nonstatic variables and methods

 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay now...What exactly are the rules for overriding a static variable or method with a non-static variable or method. And vice versa. Overriding non-static method or variable with a static method or variable
 
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 Ronnie,
1. There is only one instance of a static variable. So even if you override a static variable in a subclass, the changes are made to the one and only copy of the variable.
2. A static method cannot be overridden to be non-static. Also the other normal rules of method overriding apply.
3. For overriding the other way round, these rules will still apply.
Please correct me if I am wrong.
Cheers
Kapil
reply
    Bookmark Topic Watch Topic
  • New Topic