java - memory allocation change -


public void changecolor(int[] value)  {     color = value; } 

in above code color is int array in class. , value array in scope of method changecolor. color = value; assigning memory space allocated value color. per understanding once method ended variable specific method deleted, in case color able access value after method ends??

"will color able access value after method ends??"
short answer: yes, otherwise why define variable global.(no matter it's reference or primitive)

please run code see happens:

public class test {     int[] color = new int[2];     int = 20;     public static void main(string[] args) {         test t = new test();         t.changecolor(new int[] {1,2,3});         system.out.println(arrays.tostring(t.color));         system.out.print(t.i);      }     public  void changecolor(int[] value)      {         color = value;         = 10;     } } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -