This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jqplus

 
Vivek Shrivastava
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please modify the solution provided by me earlier
byte b=-10; instead of byte=-10;
and char c='a';instead of char='a';
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic