About Question enthuware.ocajp.i.v7.2.1065 :

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

Moderator: admin

Post Reply
DAlley
Posts: 3
Joined: Sun Oct 19, 2014 3:55 pm
Contact:

About Question enthuware.ocajp.i.v7.2.1065 :

Post by DAlley »

I would have thought that since the code that prints "4" would be unreachable, this would cause the code to not compile. I guess the compiler is not able to figure that out because the value of flag is not known until run time?

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

Re: About Question enthuware.ocajp.i.v7.2.1065 :

Post by admin »

That is correct. flag is a variable and so its value is not known to the compiler. But even if it were a constant, the code would compile because JLS permits an unreachable if block to support conditional compilation. Please see Section 14.21 (towards the end) for details.

HTH,
Paul.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 11 guests