About Question com.enthuware.ets.scjp.v6.2.150 :

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

Moderator: admin

Post Reply
dv_scjp
Posts: 1
Joined: Wed Mar 18, 2015 3:07 pm
Contact:

About Question com.enthuware.ets.scjp.v6.2.150 :

Post by dv_scjp »

Hi - I'm just starting out on the chapter-wise tests, so this is kind of a newb question:
What will the following code print?

void crazyLoop()
{
int c = 0;
JACK: while (c < 8)
{
JILL: System.out.println(c);
if (c > 3) break JACK; else c++;
}
}
I selected the answer "It will not compile" as the code displayed would NOT compile on its own. The correct answer was "It will print numbers 0 to 4" - I guess that is true if you are assuming this is in a proper class with a main method calling this method properly.

Is this a typo or are these situations common on the test (where you have to just guess at the imaginary context of the code displayed)?

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

Re: About Question com.enthuware.ets.scjp.v6.2.150 :

Post by admin »

This is a common scenario. You've have to assume a valid context.
If you like our products and services, please help us by posting your review here.

sphyror
Posts: 1
Joined: Wed Apr 14, 2021 10:14 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.150 :

Post by sphyror »

I can't understand how this line of code compiles:
JILL: System.out.println( c );

And another this can not:
JILL: int i = 0;

I thought labels are only valid for loops and I also can't understand what is the utility of the JILL lavel. I hope you can help me. Thanks.

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

Re: About Question com.enthuware.ets.scjp.v6.2.150 :

Post by admin »

That's is a rule of the Java language. A label cannot be applied on a declaration.
https://docs.oracle.com/javase/specs/jl ... l#jls-14.7

It is true that labels are mostly useful for loops. The statement JILL: System.out.println( c ); is not particularly useful.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot], pavvel and 42 guests