KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am wondering do all the local variables become static if we declare them in a static method ? for example: public static void A(){ int x [] = {3,2}; changeX(x); for (int i = 0; i< x.length; i++){ System.out.println(x[i]); // this will print -1 and 1 } } private static void changeX(int[] x){ x[0] = -1; x[1] = 1; } As far as I understand that Java is pass by value always, but why the state of X has changed after we made the changeX call ? Can anyone explain that please ? and can anyone explains how does Java deal with static variables in terms of memory allocation ? and what happen if we pass a static variable to a function as a parameter (I know people won't normally do that)
Tags (comma-separated)
Save Edits
Cancel