Online Java Compiler By
JavaTpoint.com
//import statements? import java.lang.reflect.Constructor; import java.math.BigInteger; //import public class ClassgetConstructorExample2 { public static void main(String... args) throws NoSuchMethodException { Class1 def = new Class1(); Class1 prm = new Class1(23); Class
cls = Class1.class; Constructor
constr = cls.getConstructor(); //get the default constructor System.out.println(constr); //print the constructor constr = cls.getConstructor(int.class); //get the constructor with parameter of type int System.out.println(constr); //print the constructor constr = cls.getConstructor(String.class, BigInteger[].class); //get the constructor with 2 parameter System.out.println(constr); //print the constructor } private static class Class1 { public Class1() { System.out.println("the Default Constructor... "); //default constructor } public Class1(int x) { System.out.println("this is Parameterized Constructor....(one parameter) "); } public Class1(String s, BigInteger[] integers) { //take 2 parameter System.out.println("the Parameterized Constructor....(multiple parameter) "); } } }
Output