Results 1 to 2 of 2
Thread: hiding inherited methods
- 01-05-2008, 01:33 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 35
- Rep Power
- 0
hiding inherited methods
hi,
I need to know how to hide a method from a subclass because it doesn't need it at all. I think using aggregation will solve the problem but how? do you have any examples regarding this please?
For example, if the class Dog defines the properties "bark," "fetch," and "eat food" then a class Cat can be derived from Dog by hiding "bark" and "fetch" and adding "purr" and "sleep." And then "bark" shouldn't appear in the Cat class, is using aggregation solve the problem? by putting the class Cat as "whole" and class Dog as its "part".
- 01-05-2008, 02:16 PM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 697
- Rep Power
- 6
First I think Cat should never derived from Dog, as just in a real world Cat and Dog are different species. You could create an Animal class which then can be derived by both Cat and Dog.
If you correctly define your method you should not have to do method hiding this way. In Java the access modifier such as public, protected, the default and private can be choose whether the method or field can be inherited to the child class.Website: Learn Java by Examples
Similar Threads
-
Hiding parameters from URL
By Saurabh321 in forum New To JavaReplies: 0Last Post: 02-05-2008, 12:43 PM -
abstract extended and hiding variable??
By Ace_Of_John in forum New To JavaReplies: 5Last Post: 12-23-2007, 02:46 PM -
Hiding the frame’s title bar
By Java Tip in forum Java TipReplies: 0Last Post: 12-21-2007, 08:41 AM -
Top menu fields hiding
By youayshu in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 11-13-2007, 07:10 AM -
Hiding a method or function using PHP file
By Raj Singh in forum EclipseReplies: 1Last Post: 08-09-2007, 07:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks