#196 Passing Parameters and Modifying Objects in a Method

Companies:
Skandrive
Themes:
JavaJava BasicsCode Review

What will be printed to the screen?

import java.util.*;

public class Main {
    public static void main(String[] args) {
        int a = 0;
        Integer b = 0;
        String c = new String("test0");

        List<String> d = new ArrayList<>();
        d.add("myList0");
        modify(a, b, c, d);

        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
    }

    private static void modify(int a, Integer b, String c, List<String> d) {
        a = 1;
        b = 1;
        c = "test1";
        d.add("myList1");
    }
}

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