Suppose I have 3 classes: A, DataandB
I am passing a variable from a class Athat sets the passed variable to a private variable in the class Data.
Then in the class BI want to call this variable that has been changed.
So i do
Data data = new Data();
data.getVariable();
Then it will return null, since in the class DataI initialize the variables with nothing (ex:) int v;, and I think the class Binitializes the new class and returns the default values, but I do not know how to fix it.
I know that the variable is configured correctly, because in the class A, if I do data.getVariable(), it will output the given variable.
Grade A:
Data data = new Data();
int d = 1;
data.setVariable(d);
Grade Data:
private static int b;
public void setVariable(int s)
{
b = s;
}
public int getVariable()
{
return b;
}
Grade B:
Data data = new Data();
private int v;
v = data.getVariable();
System.out.println(v);
0