fundamental Code Samples
- What's needed to be prepared for learning Java programming?
- Hello World example in Java
- Java Programming Keywords Summary
- How do I get the command line arguments passed to the program?
- How do I use Override annotation?
- How do I do bitwise exclusive OR operation?
- How do I create an inner class?
- How do I mark method as deprecated?
- How do I clone an object?
- How do I compare string regardless their case?
- What is SuppressWarnings annotation?
- How do I create type specific collections?
- How do I define constructor in enum type?
- How do I use enum in switch statement?
Page 1 of 6 |
Prev
|
Next
How do I use the instanceof keyword?
To check whether an object is of a particular type (class or interface type) you can use instanceof operator. The instanceof operator is used only for object reference variable. x instanceof y can be read as x is-a y.
The instanceof returns true if the reference variable being tested is of the type being compared to. It will still return true if the object being compared is assignment compatible with the type on the right.
For interface type, an object is said to be of a particular interface type (meaning it will pass the instanceof test) if any of the object's superclasses implement the interface.