-
Notifications
You must be signed in to change notification settings - Fork 0
Virtual Methods
Bhavanasandrala edited this page Sep 21, 2022
·
8 revisions
SystemVerilog Methods declared with the keyword virtual are referred to as virtual methods.
Virtual Methods are two types
1.Virtual Functions
2.Virtual Tasks
A function declared with a virtual keyword before the function keyword is referred to as virtual Function, we use the virtual in base(parent)class function then only child class gets executed.
Code Snippet
class packet;
string a;
int b;
function new();
a="Team";
b=4;
endfunction
virtual function void display();
$display("a=%0d",a);
$display("b=%0d",b);
endfunction
endclass
module example;
initial begin
p2=new();
p3=new();
pp0=p2;
pp1=new p3;
//p1.display();
pp0.display();
pp1.display();
//p3.e=7;
//pp1.display();
end
endmodule
Output
Task declared with a virtual keyword before the task keyword is referred to as virtual task