Class.getDeclaredMethods() has the following syntax.
public Method [] getDeclaredMethods() throws SecurityException
In the following code shows how to use Class.getDeclaredMethods() method.
/*from ww w . j a va 2s. c om*/ import java.lang.reflect.Method; public class Main { public static void main(String[] args) { MyClass cls = new MyClass(); Class c = cls.getClass(); // returns the array of Method objects Method[] m = c.getDeclaredMethods(); for (int i = 0; i < m.length; i++) { System.out.println("method = " + m[i].toString()); } } } class MyClass { public MyClass() { // no argument constructor } public void showString(String string1) { this.string1 = string1; } private void showInteger(Integer i) { this.i = i; } public Integer i = 10; private String string1 = "tutorialspoint"; }
The code above generates the following result.