public class Person {
public void sayHello() {
System.out.println("Hello!");
}
}
Class<Person> personClass = Person.class;
Method[] methods = personClass.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals("sayHello")) {
method.invoke(person, null);
}
}