Java Programming - Flow Control - Discussion

Discussion Forum : Flow Control - General Questions (Q.No. 2)
2.
switch(x) 
{ 
    default:  
        System.out.println("Hello"); 
}
Which two are acceptable types for x?
  1. byte
  2. long
  3. char
  4. float
  5. Short
  6. Long
1 and 3
2 and 4
3 and 5
4 and 6
Answer: Option
Explanation:

Switch statements are based on integer expressions and since both bytes and chars can implicitly be widened to an integer, these can also be used. Also shorts can be used. Short and Long are wrapper classes and reference types can not be used as variables.

Discussion:
16 comments Page 2 of 2.

Anish kumar said:   9 years ago
From 1.5 version all wrapper class is allowed e.g Integer, Short.
From 1.7 version string is also allowed.

Ayush said:   8 years ago
What about unboxing feature of wrapper classes which convert the wrapper class to primitive type?

AJAY said:   1 decade ago
What is the meaning of 1.4v?

Thanks in advance.

Saurabh said:   1 decade ago
About byte data type in java. ?

BrutherJ said:   1 decade ago
What Pearl said?

Suri said:   9 years ago
Correct @Anish.


Post your comments here:

Your comments will be displayed after verification.