Oracle
1Z0-851 · Question #75
Given: 1. public class Target { 2. private int i = 0; 3. public int addOne() { 4. return ++i; 5. } 6. } And: 1. public class Client { 2. public static void main(String[] args){ 3…
The correct answer is D. Line 2 of class Target can be changed to private Integer i = 0. See the full explanation below for the reasoning.
Question
Given: 1. public class Target { 2. private int i = 0; 3. public int addOne() { 4. return ++i; 5. } 6. } And: 1. public class Client { 2. public static void main(String[] args){ 3. System.out.println(new Target().addOne()); 4. } 5. } Which change can you make to Target without affecting Client?
Options
- ALine 4 of class Target can be changed to return i++;
- BLine 2 of class Target can be changed to private int i = 1;
- CLine 3 of class Target can be changed to private int addOne(){
- DLine 2 of class Target can be changed to private Integer i = 0;
How the community answered
(53 responses)- A11% (6)
- B2% (1)
- C4% (2)
- D83% (44)
Community Discussion
No community discussion yet for this question.