Given class T { int n; void set(int n) { n = n; } }, what does T t = new T(); t.set(9); System.out.println(t.n); print?
Correct answer C. 0
Explanation
Inside set, the parameter n shadows the field n, so n = n merely assigns the parameter to itself and the field stays untouched. Instance fields of type int default to 0, so 0 is printed. Writing this.n = n would reach the field and store 9. The code compiles without error, although many tools warn about it.
Answer checked How we write and check questions
Discussion