Trace the Code Output
التصميم الكائنياختبار أونلاينأساسيات كمبيوتر ساينسمتوسطآخر مرة اتسأل من 11 شهر
سؤال انترفيو في سوميرج (مصر) · المرحلة: اختبار أونلاين · المجال: التصميم الكائني وأساسيات كمبيوتر ساينس · الوظيفة: مهندس برمجيات · الصعوبة: متوسط · اتسأل مرة واحدة، آخرها أكتوبر 2025
What they ask
The 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.
A short example in the same spirit (the real one is longer and uglier):
class A {
static int n = 0;
int id;
A() { id = ++n; System.out.print("A" + id + " "); }
void hi() { System.out.print("hiA "); }
}
class B extends A {
B() { super(); System.out.print("B" + id + " "); }
@Override void hi() { System.out.print("hiB "); }
}
public class Main {
static void touch(A a) { a.id = 99; a = new A(); }
public static void main(String[] args) {
A x = new B();
x.hi();
touch(x);
System.out.print(x.id + " ");
Integer p = 127, q = 127, r = 128, s = 128;
System.out.print((p == q) + " " + (r == s));
}
}
What they look for
- Constructor chaining order (parent runs first), static counters shared across instances, dynamic dispatch on
hi(). - Java passes references by value:
touchmutates the shared object but its reassignment is invisible to the caller. - Small language traps like the Integer cache (
127boxed values compare equal with==,128do not). - Discipline: writing intermediate values in the margin instead of guessing the final line.
Expected output of the example: A1 B1 hiB A2 99 true false.