Difficulty: Easy · Puzzle 5 of 6 · Topic: Virtual Method Puzzles
Predict output when non-virtual wrapper calls a virtual hook.
class base_seq;
function void run();
$display("base run pre");
body();
$display("base run post");
endfunction
virtual function void body();
$display("base body");
endfunction
endclass
class ext_seq extends base_seq;
function void body();
$display("ext body");
endfunction
endclass
initial begin
base_seq s = new ext_seq();
s.run();
endAnalyze dispatch at each call site separately.
1) `run()` itself is non-virtual, so base wrapper always executes.
2) Inside wrapper, `body()` is virtual, so derived hook executes.
3) Output order: `base run pre`, `ext body`, `base run post`.Answer: Base wrapper runs, but virtual hook dispatches to derived body.
People often assume non-virtual wrapper blocks all polymorphism inside it.
Where is this pattern used in UVM phases and callbacks?