Java OCA OCP Practice Question 440

Question

Given the following code snippet, assuming dayOfWeek is an int, what variable type of saturday is not permitted?

final _____ saturday = 6; 
switch(dayOfWeek) { 
        default: 
           System.out.print("Another Weekday"); 
           break; 
        case saturday: 
           System.out.print("Weekend!"); 
} 
  • A. byte
  • B. long
  • C. int
  • D. None of the above


B.

Note

Any value that can be implicitly promoted to int will work for the case statement with an int input.

Since switch statements do not support long values, and long cannot be converted to int without a possible loss of data, Option B is the correct answer.




PreviousNext

Related