+ 2
What is output of this code ? Please Explain.
class A{ int attr; } class test{ static void foo(A a){ a=new A(); a.attr=2; } public static void main(String args[]) { A a=new A(); a.attr=1; foo(a); System.out.print(a.attr); } }
1 Resposta
0
1
modifying a do not modify the object it has in it at the beginning of the call of foo as you create a new instance of A