Java Program to Check Whether the Specified Class Object Represents an Interface Type or Not

You are currently viewing Java Program to Check Whether the Specified Class Object Represents an Interface Type or Not

Java program to check whether the specified Class object represents an interface type or not

// Java program to check the specified Class object 
// represents an interface type

public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class cls1 = Class.forName("Main");
    Class cls2 = Class.forName("java.lang.Runnable");

    boolean res1 = cls1.isInterface();
    boolean res2 = cls2.isInterface();

    System.out.println("Is Main an interface : " + res1);
    System.out.println("Is java.lang.Runnable an interface : " + res2);
  }
}

Output

Is Main an interface : false
Is java.lang.Runnable an interface : true

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