About Question enthuware.ocpjp.v21.2.4051 :

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

Moderator: admin

Post Reply
giginar
Posts: 21
Joined: Fri Feb 07, 2025 5:36 pm
Contact:

About Question enthuware.ocpjp.v21.2.4051 :

Post by giginar »

option 5 is trying to say, Point p1 when p1.x()>p1.y() -> true, all the other cases are false?

and also, if as explanation says, "a case null branch does not affect the exhaustiveness of a switch", why option 3 says "This switch does not cover the possibility where p is null and is therefore not exhaustive." ? thanks.

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

Re: About Question enthuware.ocpjp.v21.2.4051 :

Post by admin »

The comment in option 3 is wrong. Option 3 is incorrect not because it doesn't have case null but because the compiler cannot execute the expressions given after the when clause and it cannot determine that the two expressions x>y and x<=y cover all possibilities. (The same reason for option 4) Thus, it cannot assume it to be exhaustive. It has nothing to do with null and should be updated.

It is true that a case null branch does not affect the exhaustiveness of a switch, which means, a switch statement/expression can be exhaustive even if it does not contain a path of execution when the switch variable is null.

This has now been updated.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 105 guests