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

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

Moderator: admin

Post Reply
Talel Amira
Posts: 1
Joined: Tue Mar 26, 2013 12:58 pm
Contact:

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

Post by Talel Amira »

Hi,
I correctly answred C, but I did it because I thought that I cannot switch over a boolean. In JLS (14.11): only char, byte, short, int, Character, Byte, Short, Integer, String, or an enum type are permitted.
This is confusing!

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

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

Post by admin »

Not sure why you find it confusing. It is true that you cannot use boolean in a switch but that is not the case here anyway.
-Paul.

JaredTse
Posts: 20
Joined: Sat Apr 23, 2016 2:52 pm
Contact:

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

Post by JaredTse »

Hi,

Isn't a switch statement also not supposed to use the boolean data type ?

Thanks

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

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

Post by admin »

That is correct. That is what I said above as well.
-Paul.

flex567
Posts: 202
Joined: Mon Apr 02, 2018 8:40 am
Contact:

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

Post by flex567 »

These questions is imposible to guess correctly since no book for preparation explains much about what does/doesn't compile.

crazymind
Posts: 85
Joined: Mon Dec 24, 2018 6:24 pm
Contact:

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

Post by crazymind »

Hi, I understand the code inside switch is unreachable but does switch itself cause a compile error without any case or default label? I actually implement this code by removing the "flag = true;" and it compiles ok. So switch doesn't cause a compile error. It is ok to has no case or default label and without any code inside the block?

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

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

Post by admin »

Yes, if you have code inside a switch then that has to be associated with a case or default label. The explanation also explains the same.
Empty switch is fine as you already found out.

enthunoob
Posts: 57
Joined: Thu Apr 15, 2021 12:21 pm
Contact:

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

Post by enthunoob »

I thought it wouldn't compile cause variables i and flag are declared in the loop blocks and therefor not available outside of them.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 7 guests