Results 1 to 3 of 3
  1. #1
    kprime is offline Member
    Join Date
    Feb 2013
    Posts
    15
    Rep Power
    0

    Default Inheritance question

    Hi,

    I have a question about inheritance. I read that every class inherits from Object. Say I have a Base class that overrides equals and I have a Derived class that extends Base. So if I called super.equals() from code in the Derived class that calls the equals method of Base correct? Since every class inherits from Object, is the equals method from Object still available to code in the Derived class? How would one call the equals method from Object in Derived.

    Also if I override method in Derived, there is not way to call the Base method outside of the Derived class with an instance of Derived correct? In other words a method call is always polymorphic?

    Thank you.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,924
    Rep Power
    8

    Default Re: Inheritance question

    What happened when you put together a small example program that tested your assumptions?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,779
    Rep Power
    7

    Default Re: Inheritance question

    If the Derived class does need the equals method in Object and not the equals method in Base class then I would say that you hierarchy is wrong. If you are 100% positive that the hierarchy is correct then the Base class should not override the equals method.

Similar Threads

  1. Inheritance question
    By juxta in forum New To Java
    Replies: 2
    Last Post: 12-11-2012, 10:24 PM
  2. Inheritance hierarchy question
    By IAmACodingNoob in forum New To Java
    Replies: 3
    Last Post: 04-06-2012, 12:55 AM
  3. inheritance question
    By Jaevko in forum New To Java
    Replies: 7
    Last Post: 08-31-2011, 07:30 AM
  4. Question about inheritance
    By hei1233212000 in forum New To Java
    Replies: 3
    Last Post: 11-12-2010, 11:38 AM
  5. a question about inheritance
    By litojs in forum New To Java
    Replies: 8
    Last Post: 11-10-2008, 10:07 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
  •