Multiple choice technology programming languages

Given: class Feline { public static void main(String[] args) { Long x = 42L; Long y = 44L; System.out.print(" " + 7 + 2 + " "); System.out.print(foo() + x + 5 + " "); System.out.println(x + y + foo()); } static String foo() { return "foo"; } } What is the result?

  1. 9 foo47 86foo

  2. 9 foo47 4244foo

  3. 9 foo425 86foo

  4. 9 foo425 4244foo

  5. 72 foo47 86foo

  6. 72 foo425 86foo

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

String concatenation is left‑to‑right. The first print yields a space, then 7 and 2 become "72" surrounded by spaces. The second print concatenates "foo", 42 and 5 giving "foo425" plus a trailing space. The final println adds 42+44=86 to "foo" producing "86foo". Hence the output matches "72 foo425 86foo".