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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes