module test;
class account;
int balance;
function new(int balance = 20);
this.balance = balance;
endfunction
function int summary;
return balance;
endfunction
task deposite(input int pay);
balance = balance + pay;
endtask
task debited(input int amnt);
balance = balance - amnt;
endtask
endclass
account ac;
task account_status(account act);
if(act == null)
act = new(30);
endtask
initial begin
account_status(ac);
ac.deposite(100);
ac.debited(50);
$display(ac.summary);
end
endmodule
In reply to mohd iqbal:
You declared the argument act of the task account_status implicitly as an input. That means the value stored in ac (which is
null) gets copied to act upon entering the task. Although you construct an object and assign its handle to act, that handle value does not get copyied back to ac. To have values copied in upon entry, and copied out upon exit, you need to use the inout direction