There are three classes. One of them is parent class, and others are subclasses. For example:
Parent Class: Parent
Subclasses: SubClass1, SubClass2
My question is that how can I convert SubClass1 object into SubClass2 object without typecasting exception ?
You can’t, unless you create an is-a relationship between them. Sibling type instances cannot be cast to eachother.
You will have to do something like:
Now both inherit from
Parentand you can writeOr do the reverse.