I am having issue with passing variable value from one class to another.
I have class A and Class B bot in same package.
package D
Class A {
private int j = 0; //I have getters and setters for this variable
public void doSomething(){
j++;
this.setJ(++j);
}
}
Class B{
A a = new A();
int i = a.getJ();
System.out.println("value of j is "+i);
}
My problem is class A gets called first and j's value get incremented twice...it becomes 2. But when i am calling the getter value in i received is 0 (initial value of J).
Someone recomened since A does not know about method getJ in B i use request object to set value of j in B which i did but result is still same i am getting value as 0. I tried using request dispatchr but than also am not getting right value of J in A.
I know this is basic issue in
java if anyone canhelp me i will be really grateful.