Check whether String is an interface or class in Java


The method java.lang.Class.isInterface() is used to find if String is an interface or class in Java. This method returns true if String is an interface, otherwise it returns false.

A program that demonstrates this is given as follows −

Example

 Live Demo

package Test;
import java.lang.*;
public class Demo {
   public static void main(String[] args) {
      Class c = String.class;
      boolean interfaceFlag = c.isInterface();
      System.out.println("This is an Interface? " + interfaceFlag);
   }
}

Output

This is an Interface? false

Now let us understand the above program.

The isInterface() method is used to find if String is an interface or not. The result is stored in interfaceFlag and then displayed. A code snippet which demonstrates this is as follows −

Class c = String.class;
boolean interfaceFlag = c.isInterface();
System.out.println("This is an Interface? " + interfaceFlag);  

Updated on: 25-Jun-2020

419 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements