I am new to Java and trying to learn by myself. I wrote the below code and I was wondering why the output is not as I expect. Below is the code I have written:
public class Roughwork {
public static int classVar = 25;
public void getValue(int a){
classVar = a;
System.out.println(classVar);
}
public static void main(String[] args) {
Roughwork test = new Roughwork();
System.out.println(classVar);
test.getValue(30);
System.out.println(classVar);
}
}
and the output of this program is:
25
30
30
I expected the output to be
25
30
25
What exactly is happening and What I have to do to get my expected output?