• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic