What is the output of the following application?
public class MyClass { public static String travel(int distance) { return distance<1000 ? "train" : 10; } public static void main(String[] answer) { System.out.print(travel(500)); } }
C.
Ternary operations require both right-hand expressions to be of compatible data types.
In the code above, the first right-hand expression of the outer ternary operation is of type String, while the second right-hand expression is of type int.
Since these data types are incompatible, the code does not compile, and Option C is the correct answer.