Java Program to Demonstrate the Instanceof Operator

Java program to demonstrate the instanceof operator

// Java program to demonstrate the example of 
// "instanceof" operator

public class Main {
  public static void main(String[] args) {
    Main m = new Main();

    boolean ret = m instanceof Main;

    if (ret)
      System.out.println("The Object m is an instance of Main class");
    else
      System.out.println("The Object m is not an instance of Main class");
  }
}

Output

The Object m is an instance of Main class
Share on:

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

Leave a Comment