Archives for 

Object class in Java

java.lang.Object is the super class of all java classes by default.

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.