Getting a list of all methods of a particular class through reflection

Call getDeclaredMethods on a Class object. There is another method called getMethods but this one returns only public methods.

Main.java:

import java.lang.reflect.*;
 
public class Main {
   public static void main(String args[]) throws Exception {
      Class c = Class.forName("MyClass");   // or Class c = MyClass.getClass();
 
      Method []methods = c.getDeclaredMethods();
      for (int i=0; i<methods.length; i++) {
         System.out.println(methods[i]);
      }   
   }
}
 
class MyClass
{
   public MyClass() { }
   protected MyClass(float f) { }
 
   public String method1(int a) { return ""; }
   public float method2() { return (float) 1.2; }
   protected void method3() { }
   private double method4() { return 1.2; }
}

outputs:

public java.lang.String MyClass.method1(int)
public float MyClass.method2()
protected void MyClass.method3()
private double MyClass.method4()