Java instanceof operator
Instanceof Operator
In this article we will be discussing about Java Instanceof Operator.
The keyword instanceof is used to determine whether or not a reference variable contains a specific type of object reference.
Operators:
Instanceof Operator:
As Instanceof Operator is used to compares the instance with type, the instanceof operator in Java is also known as a type comparison operator. Either true or false is returned. Any variable that has a null value when the instanceof operator is used returns false.
Syntax:
objectName instanceOf className;
In the above syntax, if object_name is an instance of class_name, it return true value. Otherwise, it returns false value.
Example:
import java.io.*; class Prepinsta{ public static void main(String[] args){ // Initializing object of the class Prepinsta obj = new Prepinsta(); // printing the instance of the object System.out.println(obj instanceof Prepinsta); } }
Output: true
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment