bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java instanceof Keyword

❮ Java Keywords

Example

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

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

Previous

Java import Keyword

Next

Java int Keyword