Meaningless Drivel is fun!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between hidding and overridding" Watch "difference between hidding and overridding" New topic
Author

difference between hidding and overridding

Agarwal Priyanka
Greenhorn

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
Sheriff

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
sscce.org
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.


or


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.

Regards,
Phil
Agarwal Priyanka
Greenhorn

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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: difference between hidding and overridding
 
Similar Threads
Inheritance
confusing question
can static methods be overridden?
Hiding Example
Static methods and inheritance.