[Solved] Java: Creating an object, specified by a variable


In java, you can do this by using Reflection:

Reflection is commonly used by programs which require the ability to
examine or modify the runtime behavior of applications running in the
Java virtual machine.

For example:

    try {
        addObject(c.newInstance(),x,y);
    } catch (InstantiationException | IllegalAccessException e) {
        e.printStackTrace();
    }

For more about reflection, you can read here.
Hope it helps.

solved Java: Creating an object, specified by a variable