Call a method dynamically (Reflection)
import java.lang.reflect.Method; public class Main { public static void main(String s[]) throws Exception { String aClass = "Class1"; String aMethod = "class1Method1"; Class params[] = {}; Object paramsObj[] = {}; Class thisClass = Class.forName(aClass); Object iClass = thisClass.newInstance(); Method thisMethod = thisClass.getDeclaredMethod(aMethod, params); System.out.println(thisMethod.invoke(iClass, paramsObj).toString()); } } class Class1 { public String class1Method1() { return "Method1"; } public String class1Method2() { return "Method2"; } }