#182 Passing Primitives, Strings, and Arrays to Methods

Companies:
Alfa-Bank
Themes:
JavaJava BasicsCode Review

What will be printed to the screen?

public class Main {

    static int i = 1;
    static String s = "Value 1";
    static String[] strArr = new String[]{"a"};

    public static void change(int i) {
        i = ++i;
    }

    public static void change(String s) {
        s = "Value 2";
    }

    public static void changeArr(String[] s) {
        s[0] = "b";
    }

    public static void main(String[] args) {
        change(i);
        System.out.println(i);

        change(s);
        System.out.println(s);

        changeArr(strArr);
        System.out.println(strArr[0]);

    }
}

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