Write a Java program to get the class name using the object of the class


This is a simple Java program that demonstrates how to get the name of a class using the getClass() method. The program consists of a single class GetClass_Name. It creates an instance of itself and then calls the getClass() method on the instance. This method returns a Class object that represents the class of the object on which it was called. The getName() method of the Class object is used to retrieve the name of the class as a String.

In this case, the name of the class is GetClass_Name, so the program will output Print class Name : class GetClass_Name to the console.

Source Code

public class GetClass_Name
{
	public static void main(String[] args)
	{
		GetClass_Name o = new GetClass_Name();
		System.out.println("Print class Name : "+o.getClass());
	}
}

Output

Print class Name : class GetClass_Name