In this tutorial you will learn about the Java Instanceof Operator and its application with practical example.
Java instanceof Operator
In Java, the instanceof operator is used to determine whether an object is an instance of a class, a subclass, or an interface or not.
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Main { public static void main(String[] args) { String str = "W3Adda"; boolean result; result = str instanceof String; System.out.println("W3Adda - Java instanceof Operator Example."); System.out.println(result); } } |
Output:-
When you run the above java program, it will output true. It’s because str is the instance of the String class.