instanceof
operator is used to check the type of an object at runtime. It is the means by which your program can obtain run-time type information about an object. instanceof operator return boolean value, if an object reference is of specified type then it return true otherwise false. Example
interface Domestic {} class Animal {} class Dog extends Animal implements Domestic {} class Cat extends Animal implements Domestic {}
Imagine a dog object, created with Object dog = new Dog(), then:
System.out.println(dog instanceof Domestic) // true - Dog implements Domestic System.out.println(dog instanceof Animal) // true - Dog extends Animal System.out.println(dog instanceof Dog) // true - Dog is Dog System.out.println(dog instanceof Object) // true - Object is the parent type of all objects // Object animal = new Animal();, System.out.println(animal instanceof Dog) // false
This is because Dog is neither a subtype nor a supertype of Cat, and it also does not implement it.