#72 StackOverflowError During Object Creation

Companies:
Unknown company
Themes:
JavaJava BasicsCode Review

What will be printed to the screen?

public class Test {
    public static void main(String[] args) {
        User user = new User();
        user.setReferalId(112L);
    }

    static class User {
        long id;
        User referal = new User();

        public void setReferalId(long referalId) {
            this.referal.id = referalId;
        }
    }
}

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in