Program of Instanceof Operator in java


The instanceof in java is also known as type comparison operator because it compares the instance with type. The instanceof operator allows you determine the type of an object. It takes an object on the left side of the operator and a type on the right side of the operator and returns a boolean value indicating whether the object belongs to that type or no. It returns either true or false

 

 

 

 

 

 

 

 

 

 

Output:-

 

 

 

 

Some another example:

class abc

{

public static void main(String args[])

{

abc s=new abc();

System.out.println(s instanceof abc);//true

}  }

Output:    True

 

class xyz

{

public static void main(String args[])

{

xyz d=null;

System.out.println(d instanceof xyz);//false

}  }

 
Output : false

 

 

 

 

Related Posts

Comments are closed.