![]() |
VOOZH | about |
The newInstance() method of the java.lang.reflect.Constructor class is used to dynamically create objects at runtime by invoking a specific constructor through Java Reflection.
Object created
Explanation: The constructor is obtained using reflection and invoked using newInstance() to create a new object at runtime without using the new keyword.
Syntax:
constructor.newInstance(arguments);
Return Type:T - a new instance created by invoking the constructor
Example 1: Creating an Object Using a No-Argument Constructor
Output:
New Instance is created
New Instance
Explanation:
Example 2: Creating an Object Using a Parameterized Constructor
New Field
Explanation: