Page 1 of 1

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

Posted: Thu Apr 18, 2013 1:56 pm
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!

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

Posted: Thu Apr 18, 2013 7:19 pm
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.

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

Posted: Wed May 25, 2016 3:43 pm
by JaredTse
Hi,

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

Thanks

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

Posted: Wed May 25, 2016 8:30 pm
by admin
That is correct. That is what I said above as well.
-Paul.

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

Posted: Sun Dec 23, 2018 11:06 am
by flex567
These questions is imposible to guess correctly since no book for preparation explains much about what does/doesn't compile.

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

Posted: Thu Jan 10, 2019 3:31 pm
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?

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

Posted: Fri Jan 11, 2019 12:02 am
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.