Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
    • Handle and Copy Puzzles
    • Virtual Method Puzzles
      • Non-Virtual vs Virtual Through Base Handle
      • Missing super.new with Required Base Args
      • Virtual Call from Base Constructor
      • Same Name, Different Prototype: Hiding Not Overriding
      • Template Method with Non-Virtual Wrapper
      • super Method Call in Override Chain
    • Parameterized Class Puzzles
    • Factory Override Puzzles
    • OOP & Testbench Puzzles: Tricky Q&A
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Virtual Method Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Virtual Method Puzzles
  5. Template Method with Non-Virtual Wrapper
On this page

    VLSI DV Interview PuzzlesAll levels

    Template Method with Non-Virtual Wrapper

    Predict output when non-virtual wrapper calls a virtual hook.

    Puzzle

    Difficulty: Easy · Puzzle 5 of 6 · Topic: Virtual Method Puzzles

    Predict output when non-virtual wrapper calls a virtual hook.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    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;
      ext_seq  e;
      e = new();
      s = e;
      s.run();
    end

    Hint

    Analyze dispatch at each call site separately.

    Step-by-step solution

    Diagram
    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

    Answer: Base wrapper runs, but virtual hook dispatches to derived body.

    How this was checked

    Checked by running the code in Verilator 5; the printed output supports the answer above. The shown code run in Verilator: the non-virtual wrapper calls the derived virtual hook.

    Why candidates get it wrong

    The wrapper being non-virtual does not stop polymorphism inside it: `body()` is called on `this`, which is the `ext_seq` object, and `body` is virtual, so the derived hook runs.

    Interviewer follow-up

    Where is this pattern used in UVM phases and callbacks? Model answer: `uvm_sequence_base::start()` is itself a virtual task (so it is not a non-virtual wrapper), but it follows the same template shape: it sets up the sequencer and parent, then calls the virtual hooks `pre_start()`, `pre_body()`, `body()`, `post_body()` and `post_start()` in order, and you override the hooks (usually just `body()`). A cleaner non-virtual-wrapper example is the phasing machinery, which is not user-overridable and calls your virtual `run_phase`. The shared idea is a fixed outer sequence with overridable hooks. (From UVM 1.2 source and documentation; not run here.)

    Say it out loud

    The base wrapper runs, and the virtual hook dispatches to the derived body. The wrapper run is non-virtual, so it always executes, and inside it the body call is virtual. The output order is base run pre, ext body, base run post. The trap is expecting the derived class to replace the wrapper, so I would check which method is virtual.

    Related topics

    • Virtual dispatch

    • extends and super

    • Back to Virtual Method Puzzles

    • OOP & Testbench Puzzles section

    Previous

    46 / 293

    Next: super Method Call in Override Chain

    Up next

    Up nextsuper Method Call in Override Chain

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Non-Virtual vs Virtual Through Base Handle
    • Missing super.new with Required Base Args
    • Virtual Call from Base Constructor