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
    • Parameterized Class Puzzles
    • Factory Override Puzzles
      • Type Override vs Instance Override Specificity
      • create() Honors Override, new() Bypasses
      • Replace Flag in Repeated set_type_override
      • Wildcard Instance Path Precedence
      • Component Override in build_phase
      • Override Timing Relative to create Calls
    • 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

‹Factory Override Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Factory Override Puzzles
  5. Replace Flag in Repeated set_type_override

VLSI DV Interview Puzzles · All levels

Replace Flag in Repeated set_type_override

Two type overrides are applied for the same base. Predict behavior with `replace=0` and `replace=1`.

On this page

    Puzzle

    Difficulty: Medium · Puzzle 3 of 6 · Topic: Factory Override Puzzles

    Two type overrides are applied for the same base. Predict behavior with `replace=0` and `replace=1`.

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    class base_item extends uvm_object;
      `uvm_object_utils(base_item)
      function new(string name="base_item"); super.new(name); endfunction
    endclass
    class item_a extends base_item;
      `uvm_object_utils(item_a)
      function new(string name="item_a"); super.new(name); endfunction
    endclass
    class item_b extends base_item;
      `uvm_object_utils(item_b)
      function new(string name="item_b"); super.new(name); endfunction
    endclass
    
    initial begin
      base_item::type_id::set_type_override(item_a::get_type(), 0);
      base_item::type_id::set_type_override(item_b::get_type(), 0);
      $display("first=%s", base_item::type_id::create("x").get_type_name());
      base_item::type_id::set_type_override(item_b::get_type(), 1);
      $display("second=%s", base_item::type_id::create("y").get_type_name());
    end

    Hint

    Second call with `replace=0` does not overwrite existing mapping.

    Step-by-step solution

    Diagram
    1) First mapping base->item_a is installed.
    2) Second call with `replace=0` keeps existing mapping unchanged.
    3) `first` therefore prints `item_a`.
    4) Third call with `replace=1` updates mapping to item_b, so `second` prints `item_b`.

    Answer

    Answer: Output is `first=item_a` then `second=item_b`.

    Why candidates get it wrong

    Candidates forget `replace` semantics and assume latest call always wins.

    Interviewer follow-up

    Why can hidden replace defaults create flaky tests across reused env code?

    Related topics

    • Back to Factory Override Puzzles

    • OOP & Testbench Puzzles section

    Previous

    50 / 210

    Next: Wildcard Instance Path Precedence

    Up next

    Up nextWildcard Instance Path Precedence

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Type Override vs Instance Override Specificity
    • Component Override in build_phase
    • Override Timing Relative to create Calls