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)- B10% (4)
- D83% (33)
- E5% (2)
- F3% (1)
Community Discussion
No community discussion yet for this question.