Java Program to Check Anonymous Class Using IsAnonymousClass() Method

You are currently viewing Java Program to Check Anonymous Class Using IsAnonymousClass() Method

Java program to check anonymous class using isAnonymousClass() method

// Java program to check anonymous class using 
// isAnonymousClass() method

public class Main {
  public static void main(String[] args) {
    Class < ? extends Object > cls = new Object() {}.getClass();
    boolean res = cls.isAnonymousClass();

    if (res)
      System.out.println("It is an anonymous class.");
    else
      System.out.println("It is not an anonymous class.");
  }
}

Output

It is an anonymous class.

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply