What is instanceof keyword?

In Java, the instanceof keyword is used to check that the object is an instance of a class, subclass or interface.

It is also known as type comparison operator because it compares the instance with the type.

instanceof comparison returns either true or false.

public class fruits{}
public class mango extends fruits{//mango inherits fruits
public static void main(String args[]){
mango m=new mango();
System.out.println(m instanceof fruits);// will return true

Instanceof with Variable having null value

If we use the instanceof operator with any variable which has the null value than it always returns false. in other words, Instanceof Operator always returns false on a null variable.
To understand this let us have a look at the example:

public class mango{
public static void main(String args[]){
mango m=null;
System.out.println(m instanceof mango); //it will return false