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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ewebxml
Posts: 77
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

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

Post by ewebxml »

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
}
}

Kipchakbaev
Posts: 7
Joined: Sat Jan 18, 2014 8:04 am
Contact:

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

Post by Kipchakbaev »

Code: Select all

case: 200 :                //some code;
case: 300 :                //some code;
Bad syntax in code in explanation - extra colon in case

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

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

Post by admin »

Fixed.
thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest