JavaSE 面试题 成员变量与局部变量

public class Test {
    static int s;
    int i;
    int j;

    {
        int i = 1;
        i++;
        j++;
        s++;
    }

    public void test(int j) {
        j++;
        i++;
        s++;
    }

    public static void main(String[] args) {
        Test t1 = new Test();
        Test t2 = new Test();
        t1.test(10);
        t1.test(20);
        t2.test(30);
        System.out.println(t1.i + ", " + t1.j + ", " + t1.s);
        System.out.println(t2.i + ", " + t2.j + ", " + t2.s);
    }
}

参考答案

``` 2, 1, 5 1, 1, 5 ```

相关文章:

  • 2021-11-17
  • 2022-12-23
  • 2021-11-01
  • 2022-01-19
  • 2021-05-05
  • 2021-10-08
  • 2021-09-27
猜你喜欢
  • 2021-07-13
  • 2021-08-10
  • 2021-05-19
  • 2021-08-19
  • 2021-09-05
相关资源
相似解决方案