Java Program to Get the List of Constructors of a Class

You are currently viewing Java Program to Get the List of Constructors of a Class

Java program to get the list of constructors of a class

// Java program to get the list of 
// constructors of a class

import java.lang.reflect.Constructor;

public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class cls = Class.forName("java.lang.Integer");
    Constructor ctors[] = cls.getConstructors();

    System.out.println("Constructors of Integer class: ");
    for (Constructor ctor: ctors)
      System.out.println(ctor);
  }
}

Output

Constructors of Integer class: 
public java.lang.Integer(java.lang.String) throws java.lang.NumberFormatException
public java.lang.Integer(int)

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply