Operators and Assignments

Q1: 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';

A Compilation fails

B huge

C tiny

D small

ANS:A - small

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

img not found

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.