Method Overriding

In reply to harsh pandya:


class base;
 
function void display();
$display("I AM IN BASE CLASS");
endfunction
 
endclass
 
class child extends base;
 
function void display(int a); //Note this can have same signature as base as well
$display("I AM IN CHILD CLASS a =%0d",a);
endfunction

function try (); //within the 'child' scope, both methods are visible but resolved at run time based on the context.
  super.display (); 
  display (1);
endfunction
 
endclass
 
base b_h;
child c_h;
 
initial begin
c_h=new();
c_h.try ();
end