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. Virtual Call from Base Constructor

VLSI DV Interview Puzzles · All levels

Virtual Call from Base Constructor

Predict what prints and explain why this is dangerous in constructor design.

On this page

    Puzzle

    Difficulty: Hard · Puzzle 3 of 6 · Topic: Virtual Method Puzzles

    Predict what prints and explain why this is dangerous in constructor design.

    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
    class base;
      function new();
        init();
      endfunction
      virtual function void init();
        $display("base init");
      endfunction
    endclass
    
    class child extends base;
      int cfg;
      function new();
        super.new();
        cfg = 32'hCAFE;
      endfunction
      function void init();
        $display("child cfg=%0h", cfg);
      endfunction
    endclass
    
    initial begin
      child c = new();
    end

    Hint

    Consider order: base constructor body runs before derived constructor body completes.

    Step-by-step solution

    Diagram
    1) `super.new()` enters base constructor, which calls virtual `init()`.
    2) Runtime object is `child`, so dynamic dispatch chooses `child::init()`.
    3) `cfg` has not been assigned `32'hCAFE` yet, so print shows default value (typically 0).
    4) Avoid virtual callbacks from constructors unless derived state is guaranteed initialized.

    Answer

    Answer: It prints `child cfg=0` (or default), because virtual dispatch reaches child method before child constructor assigns `cfg`.

    Why candidates get it wrong

    Virtual calls in constructors can execute derived code on partially initialized objects.

    Interviewer follow-up

    What safer pattern would you use in UVM: explicit `build()` hook or post-construction init API?

    Related topics

    • Back to Virtual Method Puzzles

    • OOP & Testbench Puzzles section

    Previous

    38 / 210

    Next: Signature Mismatch Prevents Override

    Up next

    Up nextSignature Mismatch Prevents Override

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Non-Virtual vs Virtual Through Base Handle
    • Template Method with Non-Virtual Wrapper
    • super Method Call in Override Chain