Instanceof Flashcards

1
Q

The left operand of instanceof MUST…

A

be a reference variable and not a primitive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Right operand of instanceof MUST be…

A

a reference type name, i.e., a class, an interface, or an enum name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Can two wrappers of different types (for example, an Integer and a Short) be compared using ==?

A

Two wrappers of different types (for example, an Integer and a Short) cannot be compared using ==. This will lead to a compilation fail.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can an int with or any other numeric primitive b e compared with other numeric wrappers (like a Short or a Double)?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Will this code compile ?

Short k = 9; Integer i = 9; System.out.println(k == i);

A

This will not compile because k and i are referring to objects that have no IS-A relationship among themselves.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly