Hi all I'm having a bit of trouble wrapping my head around exactly what hiding a class method does, can somebody try giving it to me in plain English? I'm going by the Sun Java Tutorial but I find the example a bit vague when it comes to the hiding. I have no problem with overriding methods that seems simple enough I just can't wrap my head around why you would want to hide a class method in a subclass instead of creating a new method specific to the subclass.
comSysStudent
1
Light Poster
Recommended Answers
Jump to PostMethod hiding is same as method overriding.
In some cases, it requires that the interface will be same but the implementation will be different for superclass and subclass or the superclass method is a generic method and subclass need to implement some specific implementation. In that cases, you need to …
Jump to PostYes, you are right.
Thanks for the example, in this case -
square mysquare = new square(); shape myshape = new shape(); mysquare.area(1, 2); myshape.area(1, 2);
output for line 3 should be "square area" and line 4 should be "generic area"?
All 6 Replies
java_programmer
0
Junior Poster
comSysStudent
1
Light Poster
java_programmer
0
Junior Poster
comSysStudent
1
Light Poster
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
yasuodancez
-3
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.