File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes difference between hidding and overridding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between hidding and overridding" Watch "difference between hidding and overridding" New topic

difference between hidding and overridding

Agarwal Priyanka

Joined: Jul 25, 2008
Posts: 20
please help me with this topic giving some examples:-

what is hidding? how do it differ from overridding? give examples

keep trying...thats the way to success...<br />with best regards...<br />p.agarwal
marc weber

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

That's an important topic. The article Overriding vs. Hiding should help you understand it.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Phil Hopgood
Ranch Hand

Joined: Jul 14, 2008
Posts: 47
The "Overriding Vs Hiding" article is very interesting and illuminating. It raises a few question for me though:

I knew that if you wanted to invoke a class method then, since it's static (never becoming part of the instantiated object per se, only one copy and that in the class), it's more accurate (and clear) to use the dot operator on the class, i.e.


What confuses me is, since it's frowned upon and regarded as bad practice, why allow it at all?

Since "hiding" a class method is allowed and since you can invoke the "hiding" method through the subclass, i.e.

then you can put any functionality you like in the subclass version of the method.

So in what way is anything hidden? Granted it's not the same as overriding since it's static and you can't invoke the subclass version by using an instance variable but to me nothing seems to be hidden since if I use the right way I can use either the Foo version or the Bar version.

Agarwal Priyanka

Joined: Jul 25, 2008
Posts: 20
do you mean hidding is used only for static methods?
Rob Spoor

Joined: Oct 27, 2005
Posts: 20193

Originally posted by piyu agarwal:
do you mean hidding is used only for static methods?

And all variables, static, non-static and method-local. Sometimes hiding is also called shadowing.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: difference between hidding and overridding
It's not a secret anymore!