What is the result?

Given:
1. public class Foo {
2. int size;
3. public static void main(String[] args) {
4. Foo f = new Foo();
5. f.setSize(5);
6. Foo g = f.go(f);
7. System.out.print(f.size + ” : ” + g.size);
8. }
9. void setSize(int s) {
10. size = s;
11. }
12. public Foo go(Foo g) {
13. g.setSize(2);
14. return g;
15. }
16. }
What is the result?

Given:
1. public class Foo {
2. int size;
3. public static void main(String[] args) {
4. Foo f = new Foo();
5. f.setSize(5);
6. Foo g = f.go(f);
7. System.out.print(f.size + ” : ” + g.size);
8. }
9. void setSize(int s) {
10. size = s;
11. }
12. public Foo go(Foo g) {
13. g.setSize(2);
14. return g;
15. }
16. }
What is the result?

A.
Compilation fails.

B.
2 : 5

C.
5 : 5

D.
2 : 2



Leave a Reply 0

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