Allowed R6 · Within policy
{
"slug": "trace-the-code-output",
"title": "Trace the Code Output",
"difficulty": "medium",
"tags": [
"oop-design",
"oa",
"swe",
"fundamentals"
],
"is_free": true,
"locked": false,
"frequency": 0.25,
"last_reported_at": "2025-10-20T19:14:08.823675Z",
"url": "https://www.mokabla.com/en/c/sumerge/trace-the-code-output",
"agent": {
"page": "https://www.mokabla.com/agent/en/c/sumerge/trace-the-code-output",
"question": "https://www.mokabla.com/agent/_call/get_question?company=sumerge&question=trace-the-code-output"
},
"company": {
"slug": "sumerge",
"name_en": "Sumerge"
},
"body_md": "## What they ask\nThe first stage for associate and junior engineers is an online IQ plus technical assessment (TestGorilla). Besides multiple choice items, there is a debugging-style task: a long, deliberately messy piece of code, and you write exactly what it prints when executed. No compiler, just you and the snippet.\n\nA short example in the same spirit (the real one is longer and uglier):\n\n```java\nclass A {\n static int n = 0;\n int id;\n A() { id = ++n; System.out.print(\"A\" + id + \" \"); }\n void hi() { System.out.print(\"hiA \"); }\n}\nclass B extends A {\n B() { super(); System.out.print(\"B\" + id + \" \"); }\n @Override void hi() { System.out.print(\"hiB \"); }\n}\npublic class Main {\n static void touch(A a) { a.id = 99; a = new A(); }\n public static void main(String[] args) {\n A x = new B();\n x.hi();\n touch(x);\n System.out.print(x.id + \" \");\n Integer p = 127, q = 127, r = 128, s = 128;\n System.out.print((p == q) + \" \" + (r == s));\n }\n}\n```\n\n## What they look for\n- Constructor chaining order (parent runs first), static counters shared across instances, dynamic dispatch on `hi()`.\n- Java passes references by value: `touch` mutates the shared object but its reassignment is invisible to the caller.\n- Small language traps like the Integer cache (`127` boxed values compare equal with `==`, `128` do not).\n- Discipline: writing intermediate values in the margin instead of guessing the final line.\n\nExpected output of the example: `A1 B1 hiB A2 99 true false`.",
"follow_ups_md": "- What changes in the output if `n` is made an instance field?\n- Rewrite `touch` so the caller sees a new object.",
"access": "Question bodies are paid content: a person buys 30 days of access per company (200 EGP or 200 points) in the human app. Agents get titles, tags and difficulty; bodies only for free questions."
}