Static Class Properties and Methods
Every object has its own local variables that are not shared with any other object. When two objects of Ex_class Class is created, each object with have its own class properties(variables). In certain instances, a specific variable is required to be shared by all objects of a certain type. Declaring a global variable will make the variable visible to the entire testbench. With the OOP, a static variable can be created inside a class. This variable is shared amongst all the instances of the class.
- A static keyword is used in a class member to denote a class that has static properties or static methods.
- The static variable declared inside a class with the static keyword shares a single memory location across all the class instances.
- The static variable implies that only one copy exists.
- Static methods are the same as static variables that follow class access rules and scope.
- Static functions and tasks cannot be virtual.
- Non-static class members can not be accessible from the static method. A static method should consist of only static variables.
- Non-static functions or tasks can access static variables.
- Both static methods and static members in a class can be accessed without creating an object.
Syntax: Static Variable
static {data_type} {variable_name};
Syntax:Static Method
static {task/function} {name}();
Difference between Static Function and Function Static
Static Function | Function Static |
---|---|
Can access only static variables | Can access both static and automatic varibales |
this and super keyword cannot be used | this and super keyword can be used |
// static function example
static funtion void disp();
// execute code
endfunction
//function static example
function static void disp();
// execute code
endfunction