instanceof Operator

In addition to relational operators, there is also a type comparison operator instanceof which compares an object to a specified type. For example,


\begin{lstlisting}
class instanceofOperator {
public static void main(String[] ...
...m.out.println(''Is test an object of String? '' + result);
}
}
\end{lstlisting}

The output for above code will be Is test an object of String? true. Here, since the variable test is of String type. Hence, the instanceof operator returns true.



Subsections