• 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

final keyword can be used to avoid Overriding and Hiding.

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This post is just for information which i found very useful.
First go throgh the difference between Overriding and Hidding @
OverridingVsHiding.
Once this is clear.Now remember final keyword when applied to instance methods does not allow instance methods to be overriden by sub classes which we all know.
You can also apply final keyword to static methods which means static method in subclass that was earlier hiding the static method in parent class will now be disallowed by compiler.

Also note that all legal rules of overriding applies to hiding as well. Can someone confirm this statement? I tried and found it to be legal

For ex:

is legal but

causes compiler error.
Thanks
Deepak

[ November 30, 2007: Message edited by: Deepak Jain ]
[ November 30, 2007: Message edited by: Deepak Jain ]
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy ranchers!

Deepak wrote:


Also note that all legal rules of overriding applies to hiding as well.



I would agree. There are other things that work the same with static and instance method.
I think of access modifiers (don't have less access in hidden/overridden methods).
Or Exceptions (don't throw broader exceptions).

You can even use the @Override annotation when hiding a static method.


Yours,
Bu.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic