instanceof in Java

The Java instanceof operator is used to test whether the object is an instance of the specified type (class or subclass or interface).
The compilation check only applies when instanceof is called on a class. When checking whether an object is an instanceof an interface, Java waits until runtime to do the check. The reason is that a subclass could implement that interface and the compiler wouldn’t know it. 
The instanceof in Java is also known as type comparison operator because it compares the instance with type. It returns either true or false. If we apply the instanceof operator with any variable that has null value, it returns false.
```
class A {}
public class B extends A {
    public static void main(String[] args) {
        A a = new A();
        B b = new B();
        if(b instanceof A) 
            System.out.println("b is A");
    }
}
```
All Java classes inherit from Object, which means that x instanceof Object is usually true, except for one case where it is false. If the literal null or a variable reference pointing to null is used to check instanceof, the result is false. null is not an Object.