Originally posted by Meher Parveen:
The answer has to be A. If the object obj has been instantiated using class B, it will return a true on only 2 checks, those being:
obj instanceof B
obj instanceof A
All other instanceof checks will fail anyways.
We cannot choose option B, since an object of class A will also return true for this case!
Unfortunately, that's not the right answer. Perhaps this phrasing will help you understand the question better: suppose you know that obj can be an instance of any of A, B, C, or D. How would you write an if statement whose body gets executed
only if obj is a B object (and not an A, C, or D)? In other words, how would you fill in the condition below?