About 108,000 results
Open links in new tab
  1. The instanceof operator in Java is a binary operator used to check whether an object is an instance of a specific class, subclass, or interface. It is also referred to as a type comparison operator because it compares an object with a given type and returns a boolean value (true or false). This operator is particularly useful for ensuring type safety before performing operations like typecasting, thereby avoiding runtime exceptions such as ClassCastException.

    Key Characteristics of instanceof

    • Syntax:

    objectReference instanceof Type
    Copied!
    • Null Safety: If the object being checked is null, instanceof always returns false. This eliminates the need for explicit null checks.

    • Inheritance and Interfaces: The operator works based on the is-a relationship. For example, if a class Child extends Parent, then an object of Child will return true when checked against both Child and Parent.

    Feedback
  2. Java instanceof Operator - Baeldung

    Learn how to use the instanceof operator in Java to test if an object is of a given type. See examples, syntax, rules, and limitations of this type comparison operator.

    instanceof is a binary operator we use to test if an object is of a given type. The result of the operation is either true or false. It’s also known as a type comparison operator because it compares the instance with the type. Before casting an unknown object, the…
    See more on baeldung.com
    • Published: Jan 13, 2019
    • Java instanceof (With Examples) - Programiz

      Learn how to use the instanceof operator in Java to check if an object is an instance of a class or an interface. See examples of inheritance, polymorphism and primitive types.

    • Java instanceof Keyword - W3Schools

      Learn how to use the instanceof keyword to check whether an object is an instance of a specific class or an interface in Java. See examples, definition, usage and related pages.

    • operators - Use of "instanceof" in Java - Stack Overflow

      Basically, you check if an object is an instance of a specific class. You normally …

      • Reviews: 6
      • instanceof Keyword in Java: Usage & Examples - DataCamp

        Learn how to use the instanceof operator in Java to test if an object is an instance of a class or interface. See syntax, examples, and tips for type checking and casting.

      • People also ask
        Loading
        Unable to load answer
      • Java instanceof Keyword - Tpoint Tech

        Feb 28, 2026 · Learn how to use the instanceof operator in Java to test the type of an object and perform downcasting. See examples, syntax, and output of the operator with classes, interfaces, and …

      • Understanding the `instanceof` Operator in Java - javaspring.net

        Jan 16, 2026 · In Java, the `instanceof` operator is a powerful tool used to check whether an object is an instance of a particular class, an interface, or an array type. It plays a crucial role in runtime type …

      • Instanceof Keyword in Java - Online Tutorials Library

        Learn how to use the instanceof keyword in Java to check if an object is an instance of a specific class or interface. Explore examples and best practices.

      • Pattern Matching for instanceof - Oracle Help Center

        You can already do this with Java; however, pattern matching introduces new language enhancements that enable you to conditionally extract data from objects with code that's more concise and robust.