How to get a Java Class Object

As far as i know, there are 4 ways to get the Java Class object.

1. “.class”


Class cls = Address.class;

2. object.getClass()


Address address = new Address();
Class cls = address.getClass();

3. Class.forName()


Class cls = Class.forName("com.mkyong.io.Address");

4. ClassLoader.loadClass()


ClassLoader cl = ClassLoader.getSystemClassLoader();
Class  cls = cl.loadClass("com.mkyong.io.Address");

No comments yet. Be the first to leave a comment!

Leave a Comment

Your email address will not be published. Required fields are marked *