- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Elaborate the legal operands of the instance of operator in java?
The instanceof operator in Java is used to find whether a reference is an instance of a Type i.e. class or an interface.
Example
public class InstanceOfExample { public static void main(String args[]) { String str = "hello"; boolean bool = str instanceof String; System.out.println(bool); } }
Output
true
Legal operands of the instanceof operator
The following are the only legal operands of the instanceof operator −
- Left operand − It must be a reference representing an object.
- Right operand − It must be the name of Java class or, interface.
Except these two if you use any other operands a compile time error will be generated.
public class InstanceOfExample { public static void main(String args[]) { int i =20; boolean bool = i instanceof String; System.out.println(bool); } }
Compile time error
InstanceOfExample.java:4: error: unexpected type boolean bool = i instanceof String; ^ required: reference found: int 1 error
- Related Articles
- How can we do Python operator overloading with multiple operands?
- What are the types of Operands fetch Policies?
- Why is the movement of nerve impulses unidirectional? Elaborate.
- Evaluation order of operands in C++
- What are the schemes for checking the availability of operands?
- How many ways can get the instance of a Class class in Java?
- Instance variables in Java
- Instance variable in Java
- The new operator in Java
- Getting the type of the current instance in C#
- Differentiate between the prefix and postfix forms of the ++ operator in java?
- Importance of XOR operator in Java?
- Why subclass doesn't inherit the private instance variables of superclass in Java?
- instance initializer block in Java
- instance variable hiding in Java

Advertisements