So, I'm making a simple program that is using 2 classes.
The first class contains this:
public class A{
private int x;
public A(){
x = changexvalue(x);
System.out.println(x); //Check value
}
private int changexvalue(int x){
x = x + 2;
return x;
}
public int getxvalue(){
return x;
}
}
The second class contains this:
public class B{
public static void main(String [] args){
A a = new A();
System.out.println(a.getxvalue());
}
}
So, the problem is this. The first output(in class A) prints 2 but the class B output shows 0(I want the class B output show 2). How is this possible and how can I fix this?
Thanks