What will be printed out after the following code execution?

public class Test {

    private String name;

    Test(String name) {
        this.name =  name;
    }

    public void test(Test test) {        
        test = new Test("three");
    }

    public String toString() {
        return name;
    }

    public static void main(String[] args) {
        Test t1 = new Test("one");
        Test t2 = new Test("two");
        t1.test(t2);
        System.out.println(t2);
    }
    
}
Explanation
Object references are passed to the method by value and they cannot be changed by being reassigned to new objects.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты