Multiple choice technology programming languages

Which one is faster in java ? A. Math.max(a,b); B. (a>b)?a:b

  1. A

  2. B

  3. Both are Same

  4. None

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The ternary operator (a>b)?a:b avoids method call overhead and is executed inline by the JVM. Math.max() requires a method invocation, which involves stack frame creation and overhead even if the JIT compiler eventually inlines it. For simple comparisons, the ternary is measurably faster.