The getClass() method

The method getClass() in java.lang.object returns the runtime class of an object. The concept will be clear once we discuss an example.

package com.object;
public class Sample {
public Sample(){
}
public static void main(String[]args){
Sample sample = new Sample();
System.out.println("Runtime class of sample = "+sample.getClass());
}
}

Now let us see the output

Output

Runtime class of sample = class com.object.Sample

So the class name with package name   is the output.

One thought on “The getClass() method

  1. Pingback: Object class in Java | CoderPanda

Leave a Reply

Your email address will not be published.