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
    • Parameterized Class Puzzles
      • Global Static vs Per-Specialization Static
      • Same Specialization via typedef Alias
      • $cast Between Specializations via a Common Base
      • Unrelated Specializations Cannot Be Assigned
      • Static Function Counters Per Specialization
      • Wrong UVM Macro for Parameterized Object
    • 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

←Parameterized Class Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. OOP & Testbench Puzzles
  4. Parameterized Class Puzzles
  5. Global Static vs Per-Specialization Static
On this page

    VLSI DV Interview PuzzlesAll levels

    Global Static vs Per-Specialization Static

    Predict all printed `gid/lid` pairs and explain which counters are shared across `T` specializations.

    Puzzle

    Difficulty: Easy · Puzzle 1 of 6 · Topic: Parameterized Class Puzzles

    Predict all printed `gid/lid` pairs and explain which counters are shared across `T` specializations.

    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
    26
    class id_bank;
      static int global_id = 0;
    endclass
    
    class bucket #(type T = int) extends id_bank;
      static int local_id = 0;
      int gid;
      int lid;
      function new();
        gid = global_id;
        global_id = global_id + 1;
        lid = local_id;
        local_id = local_id + 1;
      endfunction
    endclass
    
    initial begin
      bucket#(int)  a = new();
      bucket#(int)  b = new();
      bucket#(byte) c = new();
      bucket#(byte) d = new();
      $display("a gid/lid=%0d/%0d", a.gid, a.lid);
      $display("b gid/lid=%0d/%0d", b.gid, b.lid);
      $display("c gid/lid=%0d/%0d", c.gid, c.lid);
      $display("d gid/lid=%0d/%0d", d.gid, d.lid);
    end

    Hint

    Track where each static is declared, not where constructor executes.

    Step-by-step solution

    Diagram
    1) `global_id` lives in non-parameterized `id_bank`, so all specializations share it: gids become 0,1,2,3.
    2) `local_id` lives in `bucket#(T)`, so each specialization has its own static instance.
    3) `bucket#(int)` lids are 0,1 and `bucket#(byte)` lids restart at 0,1.

    Answer

    Answer: Printed gids are 0/1/2/3 globally; lids are 0,1 for `int` and 0,1 for `byte` separately.

    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 base-class static is shared, the per-specialization static restarts for each type.

    Why candidates get it wrong

    Candidates often memorize 'statics are global' without considering parameterized specialization boundaries.

    Interviewer follow-up

    How would behavior change if `global_id` moved inside `bucket#(T)`? Model answer: it would become per-specialization like `local_id`, so the gids would restart for each type and print 0/1 for `int` and 0/1 for `byte` instead of 0/1/2/3.

    Say it out loud

    The global ids print 0, 1, 2, 3, and the local ids are 0, 1 for int and 0, 1 again for byte. The global counter lives in a non-parameterized class, so all specializations share it. The local counter lives in the parameterized class, so each specialization gets its own copy. The trap is assuming a static in a parameterized class is shared across all parameter values, so I would check where each static is declared.

    Related topics

    • Static Properties & Methods

    • Parameterized Classes

    • Back to Parameterized Class Puzzles

    • OOP & Testbench Puzzles section

    Previous

    48 / 293

    Next: Same Specialization via typedef Alias

    Up next

    Up nextSame Specialization via typedef Alias

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • $cast Between Specializations via a Common Base
    • Unrelated Specializations Cannot Be Assigned
    • Static Function Counters Per Specialization