❔ Create new instance of type unknown at runtime?
Say I have a base class,
If I have a variable:
I need to create a new instance (must call default constructor as well) of whatever
abstract class Letter with child classes A, B, and C.If I have a variable:
Letter myLetter which is of unknown type (can be any of A, B, or C, the only guarantee is it's a child of Letter), how can I create a new instance of whatever class myLetter is? I need to create a new instance (must call default constructor as well) of whatever
myLetter is and store it in another variable (say myLetter2)