Difficulty: Easy
Correct Answer: 0 0
Explanation:
Introduction / Context:
This program demonstrates parameter shadowing of instance fields by method parameters with identical names. Without qualifying with this, assignments affect only parameters, not fields, leading to unchanged instance state.
Given Data / Assumptions:
Concept / Approach:
Inside SetData, the identifiers i and j refer to the parameters, not the fields. Therefore, i = i and j = j are self-assignments on the parameters. To assign to fields, you must write this.i = i; and this.j = j;
Step-by-Step Solution:
Verification / Alternative check:
Modify SetData to use this.i and this.j, re-run, and observe “10 5.4”.
Why Other Options Are Wrong:
They assume the fields changed, which they did not due to shadowing.
Common Pitfalls:
Naming parameters the same as fields without using this; misunderstanding variable scope.
Final Answer:
0 0
Discussion & Comments