Q:

Java program to check anonymous class using isAnonymousClass() method

belongs to collection: Java Class and Object Programs

0

Java program to check anonymous class using isAnonymousClass() method

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to check anonymous class using the isAnonymousClass() method is given below. The given program is compiled and executed successfully.

// 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.

Explanation:

In the above program, we created a public class Main that contains a main() method. The main() method is the entry point for the program. Here, we checked the anonymous class using the isAnonymousClass() method. The isAnonymousClass() method returns true in the case of an anonymous class otherwise it returns false.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Class and Object Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to check whether the specified Class ... >>
<< Java program to implement cascaded method call wit...