This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes JQ+ swith question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "JQ+ swith question" Watch "JQ+ swith question" New topic
Author

JQ+ swith question

Andy Steele
Greenhorn

Joined: Jun 06, 2001
Posts: 6
Question ID :952739442080
Which of these combinations of switch expression types and case label value types are legal within a switch statement?
answers:
switch expression of type int and case label value of type char.
switch expression of type char and case label value of type byte.
My question is what about a negative byte value. That does not work...what am I missing?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
That is a rather ill-defined question. The value in a case statement is always promoted to int, so it doesn't matter whether the constant was originally defined as a byte.
What you can't have is a char type in the switch and a negative value in the case, because char can't take a negative value.
Bill

------------------
author of:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JQ+ swith question
 
Similar Threads
Jqplus
another small question
switch & case + for loop
switch statement
Switch statement