Skip to content
CodeKruPro

Mutating a parameter, then reassigning it

Predict the outputMediumJava onlyAsked in: Arista Networks
Main.java
public class Main {
    static void update(StringBuilder sb) {
        sb.append("!");
        sb = new StringBuilder("new");
        sb.append("?");
    }

    public static void main(String[] args) {
        StringBuilder text = new StringBuilder("hi");
        update(text);
        System.out.println(text);
    }
}

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in