For option a)
a. switch expression of type int and case label value of type char.
I did not select option a) because you cannot assign an 'int' to a 'char'
without an explicit cast.
Based on the code below you can switch on an int and use 'char' case labels since this code compiles.
I assume the JLS has this documented somewhere.
// ----- class SwitchInt
public class SwitchInt {
public static void main(String[] args) {
int i = 11;
switch (i) {
case 'c':
case 'd':
case 'e':
case 11:
System.out.println("Input was 11");
}
// When not using a switch
int j = 3;
char c = 1;
c = (char)j; // requires explicit cast
}
}
About Question enthuware.ocajp.i.v7.2.1357 :
Moderators: Site Manager, fjwalraven
-
- Posts: 77
- Joined: Sun Jun 30, 2013 10:04 pm
- Contact:
-
- Posts: 7
- Joined: Sat Jan 18, 2014 8:04 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1357 :
Code: Select all
case: 200 : //some code;
case: 300 : //some code;
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1357 :
Fixed.
thank you for your feedback!
thank you for your feedback!
Who is online
Users browsing this forum: Bing [Bot] and 15 guests