Since we can't use this inside a static method, and we also cannot use non-static variables, why is it that we can use objects, which use nonstatic variables inside static methods?
Here is what I mean:
public int x;
public int y;
public Account(int a, int b) {
this.x = a;
this.y = b;
}
public static void Swap(Account acc) {
int holder;
holder = acc.x;
acc.x = acc.y;
acc.y = holder;
}
So Swap() will work, even though the variables inside of the object are not static. I don't understand this part. Would appreciate some help. TIA!
xand accessingacc.x? What is the variable that Java would prevent you from referencing if it were not static? Isaccstatic?