Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Code Execution and Behavior

EasyTechnical Fundamentals00:00
Practice interviewer
In session
5 left
00:00

Your question is Code Execution and Behavior. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

BlackBerry's device-management backend team likes to open interviews with a short Java prediction exercise. Read the snippet exactly as written below.

public class DeviceCounter {
    static int counter = init();

    static int init() {
        return counter + 5;
    }

    public static void main(String[] args) {
        Integer a = 127;
        Integer b = 127;
        Integer c = 200;
        Integer d = 200;

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

What gets printed, in order, when main runs, and why? Explain your reasoning for each line rather than just stating the final output.