Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Flow Control - Switch

 
Venkat Sidh
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following types cannot be used as argument to the switch-case statement?

Choice - A) float
Choice - B) int
Choice - C) char
Choice - D) long
Choice - E) enum
Choice - F) short
Choice - G) double
Choice - H) Integer
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JLS - 14.11 The switch Statement.
 
Vaibhav Chauhan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think answer should be:

float,long,double.

Reason: all the data types that can be implicitly converted to int can be used for switch case. Integer is right answer only for java 5 because it allows autoboxing/unboxing.
Please correct me if i am wrong
 
Venkat Sidh
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't use Integer (Wrapper) in statement as a argument.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic