What is the result?

Given:

1. public class Pass {
2. public static void main(String [] args) {
3. int x = 5;
4. Pass p = new Pass();
5. p.doStuff(x);
6. System.out.print(” main x = ” + x);
7. }
8.
9. void doStuff(int x) {
10. System.out.print(” doStuff x = ” + x++);
11. }
12. }

What is the result?

Given:

1. public class Pass {
2. public static void main(String [] args) {
3. int x = 5;
4. Pass p = new Pass();
5. p.doStuff(x);
6. System.out.print(” main x = ” + x);
7. }
8.
9. void doStuff(int x) {
10. System.out.print(” doStuff x = ” + x++);
11. }
12. }

What is the result?

A.
Compilation fails.

B.
An exception is thrown at runtime.

C.
doStuff x = 6 main x = 6

D.
doStuff x = 5 main x = 5

E.
doStuff x = 5 main x = 6

F.
doStuff x = 6 main x = 5



Leave a Reply 0

Your email address will not be published. Required fields are marked *