public class test{
public static void main(String args[]){
int val = 10;
System.out.println(val);
Obj obj = new Obj();
obj.def(val);
System.out.println(val)
}
}
public class OBJ{
public void def(int val){
val = 1;
}
}
that result is same (10 , 10)
however..
public class test{
public static void main(String args[]){
double val[] = {0, 1, 2, 3, 4, 5};
Obj obj = new Obj();
for(int i = 0; i < val.length; i++){
System.out.println(val[i];
}
obj.def(val);
for(int i = 0; i < val.length; i++){
System.out.println(val[i];
}
}
}
public class OBJ{
public void def(double[] val){
for(int i = 0; i < val.length; i++){
val[i] = 1;
}
}
that is different, first print is 0 ~ 5
, however, second print is 1 , 1, 1....
I don't know what is different,
in java, Array ( it mean likes int []..) use address?? like pointer in C?
P.S : Sorry for indentation.. above code write in web,