Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.lang.reflect.Constructor;

public class Main {
    public static void main(String args[]) throws Exception {
        Class cls = Class.forName("constructor2");
        Class partypes[] = new Class[2];
        partypes[0] = Integer.TYPE;
        partypes[1] = Integer.TYPE;
        Constructor ct = cls.getConstructor(partypes);
        Object arglist[] = new Object[2];
        arglist[0] = new Integer(37);
        arglist[1] = new Integer(47);
        Object retobj = ct.newInstance(arglist);

    }
}

class constructor2 {
    public constructor2() {
    }

    public constructor2(int a, int b) {
        System.out.println("a = " + a + " b = " + b);
    }

}