About Question enthuware.ocajp.i.v8.2.1282 :

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

Moderator: admin

Post Reply
p1880554z
Posts: 2
Joined: Wed Sep 04, 2019 1:41 am
Contact:

About Question enthuware.ocajp.i.v8.2.1282 :

Post by p1880554z »

What, if anything, is wrong with the following code? void test(int x){ switch(x){ case 1: case 2: case 0: default : case 4: } }


was thinking variable x in switch is not declared since it was only visible within the method

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

Re: About Question enthuware.ocajp.i.v8.2.1282 :

Post by admin »

What happened when you tried to compile it?
If you like our products and services, please help us by posting your review here.

Seán Kennedy
Posts: 12
Joined: Wed Feb 17, 2021 6:55 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1282 :

Post by Seán Kennedy »

Hi, point 4 in the explanation, the text states
All case labels should be COMPILE TIME CONSTANTS. This means, you can have literals such as 'a', 5, 10, and true or a final variable
. This suggests that true is a valid case constant. As you cannot switch on a boolean, is this a typo?

Also, very small type in number 3 where the text states
... the following will not compile because 300 cannot...
but the code example switches on 100 and 200 (and not 300).

Kind regards,
Seán.

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

Re: About Question enthuware.ocajp.i.v8.2.1282 :

Post by admin »

You are right. As the first bullet states, boolean is not allowed for switch. 300 should indeed be 200. Fixed.
thank you for your feedback!
If you like our products and services, please help us by posting your review here.

Seán Kennedy
Posts: 12
Joined: Wed Feb 17, 2021 6:55 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1282 :

Post by Seán Kennedy »

No problem at all. I think the same typos are in the explanation for enthuware.ocajp.i.v8.2.1196 also.

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

Re: About Question enthuware.ocajp.i.v8.2.1282 :

Post by admin »

Yes, it is a common explanation displayed in multiple questions. Fixed in all.
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] and 34 guests