Sail E0 Webinar
Question


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);
}
}
Options:
A .  small
B .  tiny
C .  huge
D .  Compilation fails
Answer: Option B

This is an example of a nested ternary operator. The second evaluation (x < 22) is true, 

so the "tiny" value is assigned to sup.


Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers