nerdexam
GIAC

GSSP-JAVA · Question #95

GSSP-JAVA Question #95: Real Exam Question with Answer & Explanation

The correct answer is B. The code will not compile because 1000 is not assignment compatible with a byte data. See the full explanation below for the reasoning.

Question

Peter works as a Programmer in Magi Net Inc. He writes the following code. 1. class Ques0190{ 2. public static void main(String[] argv){ 3. byte a = 100; 4. switch(a){ 5. case 10. 6. System.out.println("ten"); 7. case 100. 8. System.out.println("hundred"); 9. case 1000. 10. System.out.println("thousand"); 11. } 12. } 13. } What will happen when Peter attempts to compile and execute the code?

Options

  • AThe code will compile and execute displaying hundred.
  • BThe code will not compile because 1000 is not assignment compatible with a byte data
  • CThe code will not compile because the argument to the switch cannot be a primitive type
  • DThe code will compile and execute displaying hundred followed by thousand.

Community Discussion

No community discussion yet for this question.

Full GSSP-JAVA Practice