nerdexam
Oracle

1Z0-851 · Question #28

Given: public class Pass { public static void main(String [] args) { int x = 5; Pass p = new Pass(); p.doStuff(x); System.out.print(" main x = " + x); } void doStuff(int x) { System.out.print("…

The correct answer is D. doStuff x = 5 main x = 5. See the full explanation below for the reasoning.

Question

Given: public class Pass { public static void main(String [] args) { int x = 5; Pass p = new Pass(); p.doStuff(x); System.out.print(" main x = " + x); } void doStuff(int x) { System.out.print(" doStuff x = " + x++); } } What is the result?

Options

  • ACompilation fails.
  • BAn exception is thrown at runtime.
  • CdoStuff x = 6 main x = 6
  • DdoStuff x = 5 main x = 5
  • EdoStuff x = 5 main x = 6
  • FdoStuff x = 6 main x = 5

How the community answered

(40 responses)
  • B
    10% (4)
  • D
    83% (33)
  • E
    5% (2)
  • F
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice