Java Constructor.newInstance() method Example

In my previous article we have seen how to use Class.newInstance() method in creating object for class dynamically but there exist a problem the newInstance() method of Class class can invoke only no-arg constructor of the class when a class has parameterized constructors we cannot use newInstance() method of Class class at that place we need to go for the newInstance() method of the Constructor class. Here also we will load the class using Class.forName() method and get the class instance and get the constructor in the class. Lets see how we can achieve it. [Read more…]