Home / Java Programming / Operators and Assignments :: Discussion

Discussion :: Operators and Assignments

  1. What will be the output of the program?

    class Test 
    {    
       public static void main(String [] args)      
       {         
          int x=20;     
          String sup = (x 15) ? "small" : (x 22)? "tiny" : "huge";            
          System.out.println(sup); 
     
        } 
    
      } 
    

  2. A.

    small

    B.

    tiny

    C.

    huge

    D.

    Compilation fails

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    This is an example of a nested ternary operator. The second evaluation (x is true, so the "tiny" value is assigned to sup.


Be The First To Comment