When the below code is executed
class Foo {
static int size = 7;
static void changeIt(int size) {
size = size + 200;
System.out.println("size in changeIt is " + size);
}
public static void main(String[] args) {
System.out.println("size = " + size);
changeIt(size);
System.out.println("size after changeIt is " + size);
}
}
the answer will be
size = 7
size in changeIt is 207
size after changeIt is 7
The answer which I expected was
size after changeIt is 207
Why the values of static variable is differing in the changeIt method and the main method ?
sizeargument inchangeItis "hiding" the static field.