Site icon Narayana Tutorial

Instance Of Operator

Instance Of Operator

Syntax:-   t instanceof x

t ==> Object / Obj reference.

x ==> class name / interface

Ex:-

To use instanceof operator some relationship  between argument type i.e either parent to child or child to parent otherwise we will get compile time error.

Where ever we are  checking parent Object is of child type or not then we will get false as the o/p.

Object  o = new Object ( c) ;

System.out.println ( o instanceof String ) ; // false

For any class or interface ‘x’  ” null instanceof x ” is always returns false.