Is it possible to create a new instance of a class whose name is in a String
variable? If so, could you please show me how it's done?
If you want to instantiate a class, and know it has a default
constructor (i.e., no parameters) then:
Class.forName(classNameAsString).newInstance();
Generally, you do this if you know it implements an interface or
abstract class. If you know nothing about the class, then you wouldn't
know what methods to call (although, you could use reflection, but
that would be somewhat random, as you wouldn't know beforehand what to
expect).
If you want to instantiate a class, and know what parameters are
passed in the constructor, you can do that as well.
Check out here:
http://javaalmanac.com/egs/java.lang.reflect/Constructors.html