Results 1 to 4 of 4
Thread: Bit confused with inheritance
- 11-22-2010, 01:30 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 26
- Rep Power
- 0
Bit confused with inheritance
Hey, I have been recently doing an assignment and have gotten myself a bit confused.
Essentially, I have 4 different classes, 1 of which is a base class and 3 of which are derived from the base class.
I now have an array which is of the same type as the base class, and if I want to insert a derived class into that array, I can do so because it inherits it's parent classes type.
Now this is where I am confused, how do I access derived classes methods when trying to access the classes through the array? It only allows me to access the base types methods.
THANKS!Last edited by blug; 11-22-2010 at 01:36 PM.
- 11-22-2010, 01:44 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 16
- Rep Power
- 0
it is not possible for u to access the method which is in derive class but not in base class as per inheritance concept bcoz u only have reference of type base class so it know about mehtod swhich are in base class
- 11-22-2010, 02:26 PM #3
You post the code template and we will help you from the place where you got stuck up.
Last edited by RamyaSivakanth; 11-22-2010 at 02:29 PM.
Ramya:cool:
- 11-22-2010, 02:44 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
You know that an object in the array is a derived class object but nothing else knows about that. You either have to cast the object you get from the array to the derived class explicitly or you have to make all methods available to the base class or you have to write a visitor object.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Confused :?
By jESTPHROSTY in forum New To JavaReplies: 2Last Post: 10-17-2010, 08:38 PM -
I am confused
By prof.deedee in forum New To JavaReplies: 6Last Post: 10-31-2009, 12:32 AM -
Confused
By coldfire in forum New To JavaReplies: 3Last Post: 01-13-2009, 02:00 PM -
a lot confused
By vineethraj in forum New To JavaReplies: 4Last Post: 01-18-2008, 01:36 AM -
what does it mean:confused:
By sivasayanth in forum New To JavaReplies: 2Last Post: 01-12-2008, 05:52 AM
Bookmarks