a method has to be defined to return one kind of thing. you can't have a method sometimes return an int and sometimes return a
String, as it would be difficult if not impossible for the calling code to know what to do. How would it know what to use to store the return value?
You can't do that. especially since the method may not know what to return until after it's been entered
but you can do this:
Now it doesn't matter. No matter what you return, it's a ParentClass object. You could do something similar by defining an interface and having your ChildA and ChildB implement the interface.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors