The
The syntax of the instanceof operator is
Object_reference instanceof ClassName/InterfaceName
The instanceof operation returns boolean value ,either true or false.
The instanceof returns true, if the object referred to by the variable on the left side of the operator passes the IS-A test for the class or interface type on the right side.
Even if the object being tested is not an actual instantiation of the class type on
the right side of the operator, instanceof will still return true if the object being
compared is assignment compatible with the type on the right.
At compile time it checks whether the type of reference variable on the left and the class or interface on the left are in the same inheritance hierarchy.Else compile-time error occurs.For example
instanceof
operator compares an object to a specified
type. You can use it to test at run-time if an object is an instance of a class, an
instance of a subclass, or an instance of a class that implements a
particular interface.The syntax of the instanceof operator is
Object_reference instanceof ClassName/InterfaceName
The instanceof operation returns boolean value ,either true or false.
The instanceof returns true, if the object referred to by the variable on the left side of the operator passes the IS-A test for the class or interface type on the right side.
Even if the object being tested is not an actual instantiation of the class type on
the right side of the operator, instanceof will still return true if the object being
compared is assignment compatible with the type on the right.
At compile time it checks whether the type of reference variable on the left and the class or interface on the left are in the same inheritance hierarchy.Else compile-time error occurs.For example