Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within OCPJP
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Programmer Certification (OCPJP)
switch type
reubin haz
Ranch Hand
Posts: 287
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Given the following code fragment switch( x ) { case 100 : System.out.println("One hundred");break; case 200 : System.out.println("Two hundred");break; case 300 : System.out.println( "Three hundred"); break; } choose all of the declarations of x that will not cause a compiler error. [Check all correct answers] a. byte x = 100 ; b. c. short x = 200 ; d. e. int x = 300 ; f. g. long x = 400 ;
Answers b and c are correct. But why a is incorrect?
Someone please explain.
SCJA, SCJP5.0, SCBCD, SCWCD
shetal bansal
Ranch Hand
Posts: 63
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Because the maximum value a byte can take is 127, so the switch case which have values greater than 127(e.g 200,300) will give compilation error.
[ June 22, 2005: Message edited by: shetal bansal ]
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
assigning an integer literal to a byte
about switch structure
Switch
Switch Statements
Selection Statements
More...