Class<?> cls = null; if (something1) { cls = new MyClass1; } else if (something2) { cls = new MyClass2; }But if you want to use reflection:
Class<?> loadMyClass(String name) { final String classname = "com.mycompany.myprogram" + name; try { return Class.forName(classname); } catch (Exception e) { return null; } }