JAVA 实例 vs 局部变量

JAVA instance vs local variable

import comp102x.IO;  
  
public class testing {
  
        private int x;

        public testing(int x) {
  
                x = x;
        }

        public static void main(String[] args) {
  
                testing q1 = new testing(10);
                IO.outputln(q1.x);
        }
}

为什么输出是 0 而不是 10?这是一个 JAVA 脚本。实例变量和局部变量的概念让我很困惑,谁能帮忙解释一下?

public testing(int x) {      
  x = x;
}

这里只是将局部变量x的值重新赋给它自己,并没有改变实例变量。

要么改变局部变量的名称,像这样:

public testing(int input) {
  x = input;
}

或者确保将值分配给实例变量,如下所示:

public testing(int x) {
  this.x = x;
}