Java instanceof is a keyword that has been mainly used for checking whether a variable is containing the given type of object reference or not. The instanceof operator of Java is known as type  comparison operator because it compares instance with type.

It can return true or may be false. Suppose we are applying instanceof with any of the variables that contain a null value in it then it will return false. We have already covered the  operators in java.

#What is the instanceof Operator

An instanceof is a binary operator used to test if an object is of a given type.

The result of the operation is either true or false. It’s also known as type comparison operator because it compares the instance with type.

Before casting an unknown object, the instanceof check should always be used. Doing this helps in avoiding ClassCastException at runtime.

#java #classcastexception #instanceof

Java instanceof Operator Example | instanceof In Java
3.15 GEEK