Class StaticField {
static int i = 7;
public static void main(String[] args) {
StaticFied obj = new StaticField();
obj.i++;
StaticField.i++;
obj.i++;
System.out.println(StaticField.i + " "+ obj.i);
}
What is the result?
A.
10 10
B.
8 9
C.
9 8
D.
7 10
so static field and obj are the same thing
confused about the variable though doesn’t static mean i can’t be changed.
or is that just for final
Answer is A
But in Eclipse you will get some warnings because you should access static fields in a static way (i.e. StaticField.i).