About Question enthuware.ocajp.i.v7.2.1157 :
Moderator: admin
-
- Posts: 1
- Joined: Tue Mar 26, 2013 12:58 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.1157 :
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!
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!
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1157 :
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.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 20
- Joined: Sat Apr 23, 2016 2:52 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1157 :
Hi,
Isn't a switch statement also not supposed to use the boolean data type ?
Thanks
Isn't a switch statement also not supposed to use the boolean data type ?
Thanks
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1157 :
That is correct. That is what I said above as well.
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1157 :
These questions is imposible to guess correctly since no book for preparation explains much about what does/doesn't compile.
-
- Posts: 85
- Joined: Mon Dec 24, 2018 6:24 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1157 :
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?
-
- Site Admin
- Posts: 10055
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1157 :
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.
Empty switch is fine as you already found out.
If you like our products and services, please help us by posting your review here.
-
- Posts: 60
- Joined: Thu Apr 15, 2021 12:21 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1157 :
I thought it wouldn't compile cause variables i and flag are declared in the loop blocks and therefor not available outside of them.
Who is online
Users browsing this forum: mcpunjabi and 45 guests