|
-
August 17th, 2009, 01:31 PM
#1
Parent access child's methods
Hi all,
I am trying to access a child's method from parent.. (it seems like the wrong thing to do, but I am kind of out of ideas)
Here is the scenario.
A parent, ParentOne, has 2 sub-classes - ChildOne and ChildTwo.
Both ParentOne, ChildOne and ChildTwo implements an interface method called - CalculateDistance().
Here is my code:
Code:
ParentOne distance;
distance = new ChildTwo();
distance.CalculateDistance();
When I execute the code, it is using the CalculateDistance() from the ParentOne, but I really want the ChildTwo's CalculateDistance() to be called.
and I can't seem to figure out the way to do it.
Any idea?
Thank you in advance for the help,
kab
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|