Given:
public class Main { public static void main(String[] args) { int x = 5;//from ww w . j a va 2 s . c o m int y = (x < 6) ? 7 : 8; System.out.print(y + " "); boolean b = (x < 6) ? false : true; System.out.println(b + " "); assert (x < 6) : "bob"; assert (((x < 6) ? false : true)) : "fred"; } }
And, if the code compiles, the invocation:.
java -ea Main
Which will be contained in the output? (Choose all that apply.)
A, D, and F are correct.
The ternary operator assigns the first value when the expression is true, so y == 7, and b == false.
The second assert statement has a ternary operator as an expression and since the result is false, fred is added to the AssertionError stack trace.