Oracle
1Z0-850 · Question #28
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…
The correct answer is D. 2 : 2. See the full explanation below for the reasoning.
Question
Given:
- public class Foo {
- int size;
- public static void main(String[] args) {
- Foo f = new Foo();
- f.setSize(5);
- Foo g = f.go(f);
- System.out.print(f.size + " : " + g.size);
- }
- void setSize(int s) {
- size = s;
- }
- public Foo go(Foo g) {
- g.setSize(2);
- return g;
- }
- } What is the result?
Options
- ACompilation fails.
- B5 : 5
- C5 : 2
- D2 : 2
How the community answered
(24 responses)- A17% (4)
- B4% (1)
- C8% (2)
- D71% (17)
Community Discussion
No community discussion yet for this question.