class parent_class;
bit [31:0] addr;
function new ();
endfunction
function display_parent();
$display("Hello world");
endfunction
endclass
class child_class extends parent_class;
bit [31:0] data;
function new ();
super.new();
endfunction
display_parent();
function display();
$display("I am lazy");
endfunction
endclass
module inheritence;
initial begin
child_class c=new();
c.display();
end
endmodule
Can anyone tell why can’t i call display_parent() function anywhere in class ?
Whether tasks and function can be called inside a function or a task. I know this is basic but i kind of forgot …
A class is an object containing properties which are a collection of variables and methods (tasks or functions). Method calls must be made from some procedural code. When do you want the display_parent() method to be called?
When I call display_parent() inside the new of the child I don’t see any issues, can you tell me why it is so ?
class child_class extends parent_class;
bit [31:0] data;
function new ();
super.new();
display_parent ();
endfunction
function display();
$display("I am lazy");
endfunction
endclass
I have seen in UVM we call functions inside build phase for ex:
Class env;
function build_phase ();
super.build_phase ();
build_ep (); // User defined function
endfunction
endclass
Does this mean function/task call must be made inside a method ?
Thanks