Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Typedef Class: A Complete Working Example

SystemVerilog Classes & OOP

Runnable example from the SystemVerilog Typedef Class tutorial (A Complete Working Example)

Open in IDE
testbench.sv
typedef class DEF;

class ABC;
  DEF def;
  int val = 10;

  function new (DEF d);
    def = d;
  endfunction

  function void show ();
    $display ("ABC.val=%0d, DEF.val=%0d", val, def.val);
  endfunction
endclass

class DEF;
  ABC abc;
  int val = 20;
endclass

module tb;
  initial begin
    DEF d = new ();
    ABC a = new (d);
    a.show ();
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.