Home > DeveloperSection > Interviews > What is java.lang.class ?

Posted on    July-04-2015 12:33 AM

 Java Java 
 1 Answer(s)
  463  View(s)
Rate this:

Mayank Tripathi
Mayank Tripathi

Total Post:807

Posted on    July-04-2015 12:33 AM

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");
 System.out.println("A and B are instances of different class");

Don't want to miss updates? Please click the below button!

Follow MindStick