File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes QID: 956597922130 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "QID: 956597922130" Watch "QID: 956597922130" New topic
Author

QID: 956597922130

Basil Shabazz
Greenhorn

Joined: Dec 05, 2001
Posts: 3
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).]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Basil
Yes, it is true that it'll tell you if the obj is an instance of class B but the way it is written it will also tell you if it is an instance of A. The question states that it wants to know if it is an isntacne of B and not A, C or D. To do what they want you would have to test for specifically class B.

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Basil Shabazz
Greenhorn

Joined: Dec 05, 2001
Posts: 3
Oh, right. I didn't pay attention to that.
Thanks Dave!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: QID: 956597922130