How to get class name from a Java object?

Example

package com.vinod.test;

public class GetClassName {

    public static void main(String[] args) {
         Integer integer=new Integer("10");
         System.out.println("Created Object "+integer);
         Class<? extends Integer> className=integer.getClass();
         System.out.println("Objects class Name "+className);
    }

}
 

Output

Created Object 10

Objects class Name class java.lang.Integer


No comments:

Post a Comment

12 classic String-based Java interview questions with simple explanations and code.

  1️⃣ Check if a String is a Palindrome Problem Given a string, check if it reads the same forward and backward. Example: "madam...

Featured Posts