+ 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); } }

29th Aug 2017, 10:40 AM
shadab gada
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
29th Aug 2017, 10:53 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar