Java Instanceof
In Java, the instanceof operator is used to check the object is an instance of the specified type or not. If the object is an instance of the specified type, then it returns true otherwise it returns false.
Syntax:
instanceof
Example:
public class SimpleinstanceOf{
public static void main(String args[])
{
SimpleinstanceOf i=new SimpleinstanceOf();
System.out.println(s instanceof SimpleinstanceOf);
}
}
Example:
To apply instanceof operator with a variable contians null value. It returns false.
public class Simpleinstance{
public static void main(String args[])
{
Simpleinstance i=null;
System.out.println(s instanceof Simpleinstance);
}
}
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com