This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between hidding and overridding

 
Agarwal Priyanka
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please help me with this topic giving some examples:-

what is hidding? how do it differ from overridding? give examples
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

That's an important topic. The article Overriding vs. Hiding should help you understand it.
 
Phil Hopgood
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you mean hidding is used only for static methods?
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic