how does this work? - Java code -
so i've got piece of code,
package test1; class student13 { public static void main(string [] args) { student13 p = new student13(); p.start(); } void start() { long [] a1 = {3,4,5}; long [] a2 = fix(a1); system.out.print(a1[0] + a1[1] + a1[2] + " "); system.out.println(a2[0] + a2[1] + a2[2]); } long [] fix(long [] a3) { a3[1] = 7; return a3; } }
can tell me why returns 15 15
, not 12 15
? function fix
applied long[] a2
, how come final result 15 15
?
you pass a1 array fix()
, called a3
in fix()
method, regardless still referencing a1
. when update a3
: a3[1]=7
, update paramater value of fix()
a1
. updated a1
!
Comments
Post a Comment