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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">