In reply to rui huang:
Hi Rui,
initial begin
my_child = new();
my_base = my_child;
my_child.display();
my_base.display();
end
It is not working because. In the class ‘base’ there is no function defined with the name display(), because of that it is giving error.
and in second post you are getting simulation results as
"
This is sub-class
This is sub-class
"
Since now you have define same function display() in ‘base’ class also.
But important is how it works.
Always remember two rules.
- Compiler check for existence of method|function in “Class of Reference|Handle” that is of LHS.
- And Execute the function|Method of Object (RHS).[If first condition passed and function is virtual (if handle of child class in the RHS)]
Summary:
Because of first rule it was not compiled.
Because of second rule you got same display.