由于我们不能this在静态方法内部使用,也不能使用非静态变量,为什么我们可以使用在静态方法内部使用非静态变量的对象呢?
这是我的意思:
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;
}
Run Code Online (Sandbox Code Playgroud)
所以Swap()将工作,即使对象内的变量不是静态的。我不明白这部分。希望能有所帮助。TIA!