Getting a list of the public constructors of a class through reflection

Call getConstructors on a Class object. There is another method called getDeclaredConstructors but this one returns all constructors, including the private and protected ones.

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();
 
      Constructor[] constructors = c.getConstructors();
      for (int i=0; i<constructors.length; i++) {
         System.out.println(constructors[i]);
      }   
   }
}
 
class MyClass
{
   public MyClass() { }
   public MyClass(int a) { }
   protected MyClass(float f) { }
   private MyClass(String s) { }
}

outputs:

public MyClass()
public MyClass(int)