Get Class Name in Java

Get Class Name in Java


In Java, just if you are given an object, you can tell the class name for which the object belongs; and also, its super classes etc. To get class name, the class you use is class Class. Do not confuse. There is a class called Class in Java like there exists Double class for data type double. This class Class you will come across in JDBC to load the driver as Class.forName().

The class Class is used extensively by Reflection.

The methods used are getClass (of Object class) and getName() (of class Class).
Following example uses these methods to get class name.

Get Class NameOutput Screenshot on Get Class Name in Java

For explanation, method signatures on the above code and for more objects refer Java get Class and get Name

Leave a Reply

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