In the following example, eye
is changed by PersonB, while leg
stays the same. This is because a private variable makes a copy of itself to the method, so that its original value stays the same; while a private static value only has one copy for all the methods to share, so editing its value will change its original value.
public class test {
private static int eye=2;
private int leg=3;
public test (int eyes, int legs){
eye = eyes;
leg=leg;
}
public test (){
}
public void print(){
System.out.println(eye);
System.out.println(leg);
}
public static void main(String[] args){
test PersonA = new test();
test PersonB = new test(14,8);
PersonA.print();
}
}
> 14 3