In this article we wre going to learn how to get class name of given object.

package com.java;
public class Sample {
    public void printClassName(Class c){
        String cname = c.getName();
        System.out.println("class name is : "+cname);
    }
    public static void main(String[] args) throws ClassNotFoundException{
        Sample s = new Sample();
        Class c = s.getClass() ;
        s.printClassName(c);
    }
}
// output : class name is : com.java.Sample