My requirement is to randomize the val1 and val2 in base class and use those members in extended class and do multiply,return.
program main;
class bin;
rand bit [3:0] val1,val2;
int val;
function new(input bit [3:0] val1,val2);
this.val1=val1;
this.val2=val2;
endfunction
function void pre_randomize();
$display(“PRE_RANDOM:Created values are val1=%d,val2=%d”,val1,val2);
endfunction
function void post_randomize();
$display(“POST_RANDOM:Created values are val1=%d,val2=%d”,val1,val2);
endfunction
virtual function void display(input int val);
$display(“multiplication of values are Val=%d”,val);
endfunction
endclass
class ext extends bin;
function new(input bit [3:0] val1_,val2_);
super.new(val1_,val2_);
$display(“Inhertited members are val1=%d val2=%d”,val1,val2);
endfunction
virtual function int mul();
$display(“Before multiplication the values created are val1=%d val2=%d”,val1,val2);
val=val1*val2;
$display("The values created are Val1=%d val2=%d",val1,val2);
return val;
endfunction
endclass
initial begin
bin bin_i=new(1,2);
ext ext_i;
if(!bin_i.randomize()) $display(“Randomization failed”);
else $display(“Randomization Passed”);
ext_i=new(bin_i.val1,bin_i.val2);
bin_i.display(ext_i.mul());
end
endprogram
Can some help me actually i am not getting randomized values in extended class to multiply.