Results 1 to 2 of 2
  1. #1
    java_fun2007 is offline Member
    Join Date
    Nov 2007
    Rep Power

    Default hiding inherited methods

    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".

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power


    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.

Similar Threads

  1. Hiding parameters from URL
    By Saurabh321 in forum New To Java
    Replies: 0
    Last Post: 02-05-2008, 12:43 PM
  2. abstract extended and hiding variable??
    By Ace_Of_John in forum New To Java
    Replies: 5
    Last Post: 12-23-2007, 02:46 PM
  3. Hiding the frameís title bar
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-21-2007, 08:41 AM
  4. Top menu fields hiding
    By youayshu in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-13-2007, 07:10 AM
  5. Hiding a method or function using PHP file
    By Raj Singh in forum Eclipse
    Replies: 1
    Last Post: 08-09-2007, 07:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts