posted 23 years ago
class A {}
class B extends A {}
class C extends B {}
class D extends C {}
The question is
Does (obj instanceof B) && ! (obj instanceof C)
correctly identifies whether the object referred to by obj was created by instantiating class B rather than classes A, C and D?
The answer is true. I agree that !(obj instanceof C) says that it does not belong to C or it's subclass D
But, how does it say that it does not belong to superclass A as
A is not mentioned in (obj instanceof B) && ! (obj instanceof C)
if the answer was
(obj instanceof B) && ! (obj instanceof C) && ! (obj instanceof A), then it is perfectly clear.
Any help is greatly appreciated.
-Jay