I suggest we should design a instance method in a class to get variable than just get class variable(especially for edit variable) There are 2 examples.
class OldA{
public int variable_A=10; // it is a class variable
}
class NewA{
private int variable_A=10; // mark it as private, so that this variable cannot be getted.
public int getVariableA(){
return variable_A;
}
}
Design an implementation class.
class TestA{
public static void main(
String args[]){
int intA;
OldA oldA=new OldA(); //Create object oldA
NewA newA=new NewA(); //Create object newA
System.out.println("oldA.variable_A="+oldA.variable_A);
oldA.variable_A=11; //Change class member of oldA
System.out.println("oldA.variable_A="+oldA.variable_A);
intA=newA.getVariableA();
System.out.println("newA.variable_A="+intA); //intA=10;
intA=intA+1;
System.out.println("newA.variable_A="+intA); //intA=11;
System.out.println("newA.variable_A="+newA.getVariableA()

; //newA.getVariableA()=10, remain unchanged
}
Use newA.getVariableA() method to get variable can protect class variable prevented from careless change.