- ✕This summary was generated using AI based on multiple online sources. To view the original source information, use the "Learn more" links.
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 TypeCopied!✕CopyNull 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.
instanceof Keyword in Java - GeeksforGeeks
Jul 23, 2025 · In Java, instanceof is a keyword used for checking if a reference variable contains a given type of object reference or not. Following is a Java program to show different behaviors of instanceof.
See results only from geeksforgeeks.orgSign In
In Java, instanceof is a keyword used for checking if a reference variable contains a given type of object reference or not. Following is a Java program to …
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.
- 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
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.