Hi all,
I am not able to understand the correct usage of instanceof operator.
consider the following example:
class Color {}
class Red extends Color {}
class Blue extends Color {}
class A {
public static void main (
String[] args) {
Color color1 = new Red(); Red color2 = new Red();
boolean b1 = color1 instanceof Color;
boolean b2 = color1 instanceof Blue;
boolean b3 = color2 instanceof Blue;
System.out.print(b1+","+b2+","+b3);
}}
I understand that instanceof operator is used to determine whether particular object is instance of particular class or not.
But i get doubts when i am doing the mock exams.
Can anyone tell me how to use them.
Thanks in advance.