permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from khalid mughal... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from khalid mughal..." Watch "Question from khalid mughal..." New topic
Author

Question from khalid mughal...

Mary Robert
Greenhorn

Joined: Jan 04, 2001
Posts: 13
hi! friends,
this is a question from khalid mughal's mock exam..
Given the following definitions, which expression identifies whether the object referred to obj was created by instantiating class B rather than classes A, C and D?
class A {}
class B extends class A{}
class C extends class B{}
class D extends class A{}
Select all valid answers.
(a) obj instanceof B
(b) obj instanceof A && !(obj instanceof C)
(c) obj instanceof B && !(obj instanceof C)
(d) !(obj instanceof C | | obj instanceof D)
I thought the answer would be a & c. but it is given that the answer is only c. why? can anyone give a detailed explanation for this?
and one more thing is.. I scored 72% in this mock exam. Will I be
able to pass the actual exam???
Thank U
Mary.
Tom Tang
Ranch Hand

Joined: Dec 24, 2000
Posts: 133
Choice a only insures obj is an instance of B, but can't guarantee it's not instantiated by C, which is a subclass of B(and therefore "is a B".)
Only Choice C is Valid, because it insures that obj is NOT an instance of C, and therefore can only be instantiated by B in this case.
By the way, Here is the author's original explanation for this question in his book:

The important thing to remember is that if an object is an instance of a class, then it is also an instance of all the superclasses of this class.

[This message has been edited by Tom Tang (edited February 15, 2001).]
[This message has been edited by Tom Tang (edited February 15, 2001).]


Sun Certified Java Programmer
Tom Tang
Ranch Hand

Joined: Dec 24, 2000
Posts: 133
Dear Mary:
If you get that score in Khalid's test. I'm pretty sure you will get more 80% in the real test. It is widely believed that Khalid's mock is tougher (not just slightly) than the real test.
Mary Robert
Greenhorn

Joined: Jan 04, 2001
Posts: 13
Thank U Tom.
Alamu Vinai
Greenhorn

Joined: Feb 01, 2001
Posts: 19
I can't understand the question. Can anyone explain this?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from khalid mughal...
 
Similar Threads
PGJC mock exam question
instanceof operator
instanceof operator
How to check the class of an Object given its reference?
Doubt in instanceof operator