What is the result of the following code execution?

1: class Foo {
2:   public static void main(String[] args) {
3:     Integer i = 42;
4:     String s = (i < 40) ? "life" : (i > 50) ? "universe" : "everything";
5:     System.out.print(s);
6:   }
7: }
Explanation
Ternary operator does this, in a way:

if (i < 40) { //false
    return "life";
} else if (i > 50) { //false
    return "universe"
} else { 
    return "everything"
}
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback