About Question enthuware.ocpjp.v7.2.1228 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
mchristiaan
Posts: 4
Joined: Sat Aug 08, 2015 8:01 pm
Contact:

About Question enthuware.ocpjp.v7.2.1228 :

Post by mchristiaan »

if obj instanceof B is true; this means that obj is also instanceof A right? Please help me understand the correct expression (obj instance B) && !(obj instanceof C) in the Explanation part.

admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1228 :

Post by admin »

There is a detailed explanation given with this question. Can you please go through it and specify which part is not clear so that I can clear your doubt?
Paul.
If you like our products and services, please help us by posting your review here.

mchristiaan
Posts: 4
Joined: Sat Aug 08, 2015 8:01 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1228 :

Post by mchristiaan »

Paul

The explanation states "The given expression will not be able to distinguish between an object of class A and an object of class B. It will return true in both the cases........Correct expression would be (obj instanceof B) && ! (obj instanceof C). This will return true only if obj points to an object of class B and not of A, C, or D. --> Shouldn't the last sentence be: This will return true only if obj points to an object of class B and not of C, or D. Because if obj is instance of B means it's also instance of A since B extends A?

admin
Site Admin
Posts: 10045
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1228 :

Post by admin »

Yes, an instance of B is also an instance of A. But an instance of A doesn't mean it is an instance of B. So if obj points to an instance of A, then "obj instanceof B" will be false. Therefore, the expression will return false in the case of A also and not just C and D.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests