I have written a simple example to understand polymorphism better.
module poly_case4;
class BaseC;
virtual function void func1;
$display ("func1 in BaseC");
func2;
endfunction
function void func2;
$display ("func2 in BaseC");
endfunction
endclass: BaseC
class DerivedC extends BaseC;
function void func1;
$display ("func1 in DerivedC");
func2;
endfunction
function void func2;
$display ("func2 in DerivedC");
endclass : DerivedC
BaseC P1 ;
DerivedC P2 = new;
initial begin
P1 = P2;
P1.func1;
end
endmodule
Please note that, func2 is not defined as virtual.
So, P1.func1 is called, I expected late binding based for func1 and get resolved to DerivedC.func1
But since func2 is not defined as virtual, I expected func2 to be called from BaseC.func2
In reality, DerivedC.func2 is being called.
So, how does polymorphism work actually?
In the above case, there is no late binding as far as func2 is concerned and it applies only for func1?