A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to demonstrate the instanceof operator
Q:

Java program to demonstrate the instanceof operator

0

Java program to demonstrate the instanceof operator

All Answers

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

In this program, we will check an object of an instance of a particular class or not using "instanceof" operator. It returns the Boolean value truefalse.

Program/Source Code:

The source code to demonstrate the "instanceof" operator is given below. The given program is compiled and executed successfully.

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

Explanation:

In the above program, we created a class Main. The Main class contains a method main(). The main() method is an entry point for the program. Here, we created the object m of Main() class and checked 'm' is an instance of class Main or not using the "instanceof" operator and printed the appropriate message.

 

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now