When JVM creates an instance of a class, it creates an object "java.lang.Class object" which describes the type of the object. This class object is shared by all the objects of a class. If you want to access the class object of an instance, use getClass() method of the object. This method is inherited from java.lang.Object
Ex: Created two instances class called Programmer
Programmer A = new Programmer(); Programmer B = new Programmer(); // For check Instances if(A.getClass() == B.getClass()) { System.out.println("A and B are instances of same class"); }else{ System.out.println("A and B are instances of different class"); }
Liked By
Write Answer
What is java.lang.class ?
Join MindStick Community
You have need login or register for voting of answers or question.
Anonymous User
04-Jul-2015