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

Scope Resolution Operator: Accessing Static Methods and Variables

SystemVerilog Advanced Features

Runnable example from the SystemVerilog Scope Resolution Operator tutorial (Accessing Static Methods and Variables)

Open in IDE
testbench.sv
class ABC;
	static int 	data;

	static function void display();
		$display("data = 0x%0h", data);
	endfunction
endclass

module tb;
	initial begin
      	ABC a1, a2;

      	// Assign to static variable before creating
      	// class objects, and display using class_type and
      	// scope resolution operator
		ABC::data = 32'hface_cafe;
		ABC::display();
  
      	a1 = new();
      	a2 = new();
      	$display ("a1.data=0x%0h a2.data=0x%0h", a1.data, a2.data);
	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.