What will be printed out as a result of the following code execution / compilation?

public class Test {

    private String name;

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

    public void test(final 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
final parameter in the test method says that the reference to test object can not be modified. Therefore the "test = new Test ("three")" string will result in a compilation error.

Follow CodeGalaxy

Mobile Beta

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