VLSI DV Interview Puzzles · All levels
super Method Call in Override Chain
A derived override calls `super.report()`. Predict final string and explain call chain.
Puzzle
Difficulty: Hard · Puzzle 6 of 6 · Topic: Virtual Method Puzzles
A derived override calls `super.report()`. Predict final string and explain call chain.
Code
systemverilog
class base_r;
virtual function string report();
return "B";
endfunction
endclass
class mid_r extends base_r;
function string report();
return {"M-", super.report()};
endfunction
endclass
class ext_r extends mid_r;
function string report();
return {"E-", super.report()};
endfunction
endclass
initial begin
base_r h = new ext_r();
$display("%s", h.report());
endHint
`super` is lexical (next class in inheritance chain), not dynamic back to most-derived.
Step-by-step solution
diagram
1) Dynamic dispatch picks `ext_r::report` for `h.report()`.
2) `ext_r` calls `super.report()` => `mid_r::report`.
3) `mid_r` calls its `super.report()` => `base_r::report`.
4) Concatenation yields `E-M-B`.Answer
Answer: Final output is `E-M-B`; dynamic entry is most-derived, then explicit `super` walks up one lexical level each call.
Why candidates get it wrong
Some candidates think `super` re-dispatches dynamically and can recurse to most-derived.
Interviewer follow-up
How would behavior change if `mid_r::report` were declared non-virtual?