An instance variable is one per Object, every object has its own copy of instance variable.
A static variable is one per Class, every object of that class shares the same Static variable.
class MyStaticClass{
private static int myStaticInt;
public static int getMyStaticInt() {return myStaticInt;}
}
class MyInstanceClass{
private int myNonStaticInt;
public int getMyNonStaticInt() {return myNonStaticInt;}
}
Is there a performance difference between either? Is it more expensive to call one over the other?
int i = MyStaticClass.getMyStaticInt();
OR:
int i = new MyInstanceClass().getMyNonStaticInt();