I found this true/false question on JQPlus:
Given the following class definitions, the expression
(obj instanceof A) && ! (obj instanceof C) && ! (obj instanceof D)
correctly identifies whether the object referred to by obj was created by instantiating class B rather than classes A, C and D?
class A {}
class B extends A {}
class C extends B {}
class D extends C {}
I selected true. The correct answer is stated as false. The JQPlus explaination says: "Correct answer would be (obj instanceof B) && ! (obj instanceof C)".
I've tested this question by compiling all four classes and adding this main method to class B:
<CODE>
public static void main(String args[])
{
B obj = new B();
System.out.println((obj instanceof A) && !(obj instanceof C) && !(obj instanceof D));
}
</CODE>
After running B, the result is true. Since class A is a superclass of class B, shouldn't the correct answer to this question be true? I'm still a rookie at all this so I'm not sure, would love some feedback.
Thanks.
[This message has been edited by Basil Shabazz (edited December 08, 2001).]
[This message has been edited by Basil Shabazz (edited December 08, 2001).]
[This message has been edited by Basil Shabazz (edited December 08, 2001).]