WHAT IS JAVA.LANG.CLASS ?

Mayank Tripathi

Total Post:807

Points:4035
Posted by  Mayank Tripathi
Java 
 650  View(s)
Ratings:
Rate this:
  1. Mayank Tripathi

    Post:807

    Points:4035
    What is java.lang.class ?

    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");
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!