Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

Java instanceof Keyword

❮ Java Keywords


Example

Check whether an object is an instance of a specific class:

public class MyClass {
  public static void main(String[] args) {
    MyClass myObj = new MyClass();
    System.out.println(myObj instanceof MyClass); // returns true
  }
}

Run example »


Definition and Usage

The instanceof keyword checks whether an object is an instance of a specific class or an interface.

The instanceof keyword compares the instance with type. The return value is either true or false.


Related Pages

Read more about objects in our Java Classes/Objects Tutorial.


❮ Java Keywords