java newinstance

Java newInstance

With Java newInstacnce() of class Class, we can create an object as you will do with new keyword. Example on Java newInstance public class Student { int marks; public void display() { System.out.println(“Hello 1”); } public static void main(String args[]) throws InstantiationException, IllegalAccessException, ClassNotFoundException { Student std1 = new Student(); std1.marks = 50; Class cls1 …

Java newInstance Read More »

forName() newInstance() Methods in Java

forName() newInstance() Methods: We have seen earlier, how to create an object without new keyword by cloning using the marker interface Cloneable. Now, Let is us see another style using forName() and newInstance() methods of class java.lang.Class. Example on using forName() newInstance() methods to create an object without new keyword public class Demo { int …

forName() newInstance() Methods in Java Read More »