This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# Jqplus

Vivek Shrivastava
Ranch Hand
Posts: 277
Hi,
This is from jqplus exam.
Q
Which of these combinations of switch expression types and case label value types are legal within a switch statement?

One of the answer is :
Switch expression of type char and case label of valur type byte

my doubt here is, what if case label have a -ve value because byte can have a -ve value.
am i making any sence here??

vivek
[This message has been edited by Vivek Shrivastava (edited August 12, 2000).]

Ken Lai
Ranch Hand
Posts: 30
Yeah I'm quite confused with the legal types in a switch statement. For example:
byte b = 10;
switch(b)
{
case 'a' :
break;
}
is legal but how is the conversion done? I mean if we assign a char to a byte the compiler would complaint but not in this case.

Anonymous
Ranch Hand
Posts: 18944
Originally posted by Vivek Shrivastava:
Hi,
This is from jqplus exam.
Q
Which of these combinations of switch expression types and case label value types are legal within a switch statement?
[b]
One of the answer is :
Switch expression of type char and case label of valur type byte

my doubt here is, what if case label have a -ve value because byte can have a -ve value.
am i making any sence here??

vivek
[This message has been edited by Vivek Shrivastava (edited August 12, 2000).][/B]

U will get error as value too large.Since not compatible
with range of char.

sanjay gautam
Ranch Hand
Posts: 35
class Test{
public static void main(String[]s){
char='a';
byte=-10;
switch(b){
case 1:System.out.println(" i am in case one");
break;
case (-10):System.out.println(" i am in case byte");
break;
case 'a':System.out.println(" i am in case 'a'");
break;
}
}
}
try this it will work. thanks for a tricky question.

sanjay gautam
Ranch Hand
Posts: 35
please modify the solution provided by me earlier