Java Programming/Keywords/instanceof

is a keyword.

It checks if an object reference is an instance of a type, and returns a boolean value;

The   will return true for all non-null object references, since all Java objects are inherited from. will always return if  is.

Syntax:  TypeName

For example:

Run the program: java Test The output:

Note that the operator can also be applied to interfaces. For example, if the example above was enhanced with the interface

and the classes modified such that they implemented this interface

we could ask if our object were edible.