Static Properties and Methods
Static Properties and Methods
A static keyword is used in a class member to denote class has static properties or static
methods. It acts as global
Both static methods and static members in a class can be accessed without creating an
object.
Example:
//static properties
class transaction;
static int a;
int b;
function new();
a++;
b++;
endfunction
endclass
module tb;
transaction tx[4];
initial begin
foreach(tx[i]) begin
tx[i]=new();
end
end
@shraddha_pawankar Date:15/08/23
endmodule
output :
# KERNEL: value of a=1 b=1
# KERNEL: value of a=2 b=1
# KERNEL: value of a=3 b=1
# KERNEL: value of a=4 b=1
https://www.edaplayground.com/x/mb8H
class transaction;
s_id++;
endfunction
endclass
module class_example;
transaction tr;
initial begin
end
@shraddha_pawankar Date:15/08/23
endmodule
Output:
# KERNEL: After incr_id function call
# KERNEL: Value of s_id = 2 using tr handle
# KERNEL: Value of s_id = 2 using scope resolution operator
https://edaplayground.com/x/cxf7
These tasks or functions can be called without creating an instance of the module.
static methods belong to a class rather than an instance and are used for operations that
are not tied to a specific instance of the class.
They provide utility or common functionality that can be accessed without creating
objects.
In SystemVerilog, you can use tasks or functions to encapsulate reusable operations without
creating an instance of a module.