Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inheritance and multiple method overrides

Status
Not open for further replies.

AquaShift

Programmer
Mar 24, 2004
1
US
I created 3 classes, the superclass, or grandparent, the parent, and the child.

In my abstract defined superclass, I declared an abstract method that I would be overriding in subsequent classes that inhereted from the superclass.

In my parent class, I redefined the method, keeping the same argument list and name, otherwise known as 'overriding'.

I did the same in the child class, overriding the same method again, with different definition but same argument list and name.. And it let me compile.


I then created a 4th class, which had my
'public static void main(String[] args)' method.
In that method I created class objects for both the parent
and the child classes..
With those objects, I called both the parent and class methods that were overridden from the superclass.
It let me compile.. But when I executed the program,
the PARENT overridden method got called twice..

even though the code was.

<parentclassobject>.overriddenMethod();
<childclassobject>.overriddenMethod();


I need to fix this code by today or tomorrow. Will someone please help me with this.

 
with different definition but same argument list and name"

What are you considering to be a "definition"? Are you absolutely sure the argument list and name is exactly the same? (name case sensitive, etc.)

If you could post some code, it would be helpful...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top