Instanceof Flashcards
The left operand of instanceof MUST…
be a reference variable and not a primitive.
Right operand of instanceof MUST be…
a reference type name, i.e., a class, an interface, or an enum name.
Can two wrappers of different types (for example, an Integer and a Short) be compared using ==?
Two wrappers of different types (for example, an Integer and a Short) cannot be compared using ==. This will lead to a compilation fail.
Can an int with or any other numeric primitive b e compared with other numeric wrappers (like a Short or a Double)?
Any two numeric primitives can be compared using == operator.
Even a numeric primitive and a primitive wrapper (for example, an int with a Short or a Double) can be compared.
Will this code compile ?
Short k = 9; Integer i = 9; System.out.println(k == i);
This will not compile because k and i are referring to objects that have no IS-A relationship among themselves.