Originally posted by Pankaja Shinde:
I found this question on Mock exam.
Which of the following statements are true?
1) The instanceof operator can be used to determine if a reference is an instance of a class, but not an interface.
2) The instanceof operator can be used to determine if a reference is an instance of a particular primitive wrapper class
3) The instanceof operator will only determine if a reference is an instance of a class immediately above in the hierarchy but no further up the inheritance chain
4) The instanceof operator can be used to determine if one reference is of the same class as another reference thus
Answer is 2.
Can anyone explain me.
I think question is wrong.
Regards
1 is certainly not true. 3 is not true. 4 is not true because instanceof cannot be used between references.
So by the process of elimination, if one of the answers has to be true, then 2 is correct.
Also simply by looking at option 2, there is nothing unreasonable there.