What is the use of instanceof operator in Java?

CWC
2 Min Read

Instanceof operator is an operator used in java which helps to check whether the given object is of the Instance type by the combination of different types of data such as a subclass,class or a Interface.Instanceof operator helps to perform many function as it perform the work of a comparator too.It compares the value and provides the result in the true or false form.Hence the Instanceof operator is also called as a comparator operator.

Instanceof operator acts as an comparator and if we compare variables which has null value the result is always false from the Instanceof operator.Instanceof operator is being specified in the system print line itself.For example if a class tries to extends the other class with the help of inheritance then when we used to implement then the output will be true.And if we specify a name that has null value and has nothing to read then the Instanceof provides a false value straight away.

Instanceof operator also perform downcasting which means whenever the parent class objects is being reffered then it is called as downcasting because it perform action from bottom to top.But Whenever the user tries to perform this task then the user get the compilation error as in java it is not possible at any case.Downcasting is only possible if we perform or take the help of Instanceof operator.Instanceof operator help to provide the user a runtime information Whenever the user request it.Casting of objects at runtime is one of the objective of Instanceof operator.

Instanceof operator is one of the helpful operator used in java which is used to perform many activity at the real time.Instanceof operator help us to check a real time collection of objects.It also help to determine the types of objects to be used.Apart from that the Instanceof operator can be rectified as an identifier.Its main function is to perform comparison.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version