Is it possible to call a method within a child class from within the parent class?
If it is how do I do it; if not what is an alternative?
Printable View
Is it possible to call a method within a child class from within the parent class?
If it is how do I do it; if not what is an alternative?
To me that would smell of a very broken design. I'd rethink the overall design of your program so that you don't require this.
Either that or give us an explanation why you think you need this and perhaps we can help you find alternatives.
Actually, I just started using java and I am only now learning about design structure and inheritance, etc., so I wanted to know if it was possible/practical.
After posting here I did some looking on the web and I realized that it isn't done, so I made the method call from main instead.
Any advice is welcome.
Thanks for the reply.
The idea is, given that the object is of type SuperClass, how are we supposed to know if it is SubClassA, SubClassB, or so forth? We don't, so we can't.
Unless we typecast, which we don't want to do in OOP.