Java Reflection: Difference between getMethods() and getDeclaredMethods()

Can someone please elaborate on this, and explain the difference between the two methods, and when/why you would want to use one over the others


getDeclaredMethods includes all methods declared by the class itself, whereas getMethods returns only public methods, but also those inherited from a base class (here from java.lang.Object).

Read more about it in the Javadocs for getDeclaredMethod and getMethods.