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. Non-Virtual vs Virtual Through Base Handle
On this page

    VLSI DV Interview PuzzlesAll levels

    Non-Virtual vs Virtual Through Base Handle

    A framework stores derived objects in base handles. Predict output and explain why only one method dispatches to derived.

    Puzzle

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

    A framework stores derived objects in base handles. Predict output and explain why only one method dispatches to derived.

    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
    25
    class checker_base;
      function string mode();
        return "BASE";
      endfunction
      virtual function string detail();
        return "base-detail";
      endfunction
    endclass
    
    class checker_ext extends checker_base;
      function string mode();
        return "EXT";
      endfunction
      function string detail();
        return "ext-detail";
      endfunction
    endclass
    
    initial begin
      checker_base c;
      checker_ext  e;
      e = new();
      c = e;
      $display("mode=%s detail=%s", c.mode(), c.detail());
    end

    Hint

    Dispatch behavior is determined by virtual-ness in the base declaration.

    Step-by-step solution

    Diagram
    1) `mode()` is non-virtual in base, so call binds statically to `checker_base::mode`.
    2) `detail()` is virtual in base, so call dispatches dynamically to `checker_ext::detail`.
    3) Output becomes `mode=BASE detail=ext-detail`.

    Answer

    Answer: Output is `mode=BASE detail=ext-detail`; non-virtual methods bind to static handle type while virtual methods use runtime object type.

    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: only the virtual method dispatches to the derived class.

    Why candidates get it wrong

    Declaring a method in the derived class does not create polymorphism unless the base declaration is virtual; the call site's handle type decides for `mode()`.

    Interviewer follow-up

    If `mode` is made virtual only in derived, does behavior change through `checker_base` handle? Model answer: no. `c.mode()` still prints `BASE` because the base declaration is non-virtual and the call binds to the handle type; only a call through a `checker_ext` handle (`e.mode()`) sees `EXT`, and it starts a new virtual chain for further subclasses. (Verified in Verilator.)

    Say it out loud

    The output is mode equals BASE and detail equals ext-detail. A non-virtual method binds to the type of the handle, so mode runs the base version. A virtual method dispatches on the type of the actual object, so detail runs the extended version. The trap is assuming every method behaves polymorphically, so I would check which methods are declared virtual in the base.

    Related topics

    • Virtual dispatch

    • extends and super

    • Back to Virtual Method Puzzles

    • OOP & Testbench Puzzles section

    Previous

    42 / 293

    Next: Missing super.new with Required Base Args

    Up next

    Up nextMissing super.new with Required Base Args

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Virtual Call from Base Constructor
    • Same Name, Different Prototype: Hiding Not Overriding
    • Template Method with Non-Virtual Wrapper