posted 17 years ago
Hi All,
I want trap the class name of an incoming object.
Here is the scenario
I have a super class Parent & have 5 derived classes which extend Parent say Child1, Child2, Child3 , Child4, Child5.
Now the child(n) object is sent to me after doing an upcast.
Parent p = new Child1();
It could be an instance of Child2 , or Child3 so on
Now in my code I want to determine what is the type of the Child class object by using the Parent reference (p) as mentioned above.
Is there a way to do that without resorting to the (instanceof) operator.
Say in a scenario where in I dont know what all subclasses does the Parent class have so I can avoid all the numerous if conditions.
Do post your thoughts on the same
Regards