How many ways can get the instance of a Class class in Java?



You can create an object of the class named Class in two ways −

Using new keyword as −

Class obj = new Class();

Using the forName() method of the class named Class.

Class obj = Class.forName("DemoTest");
Monica Mona
Monica Mona

Student of life, and a lifelong learner


Advertisements