HOME      BLOG       FORUMS      CONTACT       ABOUT

Create an object of a class without new keyword.

The newInstance method of Class class can be used for creating an object of a class without using new keyword.

public class ClazzUtil {
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
		Class clazz = Class.forName("java.lang.Thread");
		Thread obj = (Thread) clazz.newInstance();

		System.out.println(obj);
	}
}

Share

Tags: , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button

Leave a Reply