-4
public class Main {
    static class Test {
        int x;
    }

    public static void main(String[] args) {
        Test t = new Test(); 
        t.x = 10; int a = 10; 
        String s = "s"; test(a, s, t); 
        System.out.println(t.x); //Output 10 } 
    }

    static void test(int x, String y, Test t) {
        x = 5;
        y = "a";
        t = new Test();
        t.x = 5;
        System.out.println(t.x); //Output 5 }
    }
}
OH GOD SPIDERS
  • 2,694
  • 2
  • 12
  • 15
  • 1
    [Is Java "pass-by-reference" or "pass-by-value"?](https://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-by-value) – QBrute May 31 '22 at 09:56
  • `t = new Test()` in `test()` only changes the local parameter; it does not change `t` in `main` – user16320675 May 31 '22 at 10:16

0 Answers0