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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • 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
      • Signature Mismatch Prevents Override
      • 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
  • Interview Prep: Puzzle Rounds5
  • 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

VLSI DV Interview Puzzles · All levels

Template Method with Non-Virtual Wrapper

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

On this page

    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
    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();
    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.

    Why candidates get it wrong

    People often assume non-virtual wrapper blocks all polymorphism inside it.

    Interviewer follow-up

    Where is this pattern used in UVM phases and callbacks?

    Related topics

    • Back to Virtual Method Puzzles

    • OOP & Testbench Puzzles section

    Previous

    40 / 210

    Next: super Method Call in Override Chain

    Up next

    Up nextsuper Method Call in Override Chain

    Sign in to save progress

    Practice this lessonReport an error

    See also

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