Home / Java Programming / Flow Control :: Discussion

Discussion :: Flow Control

  1. What will be the output of the program?

     Float f = new Float("12"); 
     switch (f) 
     {    
         case 12: System.out.println("Twelve");     
         case 0: System.out.println("Zero");     
         default: System.out.println("Default");  
    } 
    

  2. A.

    Zero

    B.

    Twelve

    C.

    Default

    D.

    Compilation fails

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    The switch statement can only be supported by integers or variables more "narrow" than an integer i.e. byte, char, short. Here a Float wrapper object is used and so the compilation fails.


Be The First To Comment