Hi, I am trying basic oops concept, and i came across something new for me.
module wo_object();
class a;
function void display();
$display("in class A ");
endfunction
endclass
class b extends a;
function void display();
$display("in class b");
endfunction
endclass
initial begin
a a1;
b b1;
a1.display();
b1.display();
end
endmodule
i am getting output as
in class A
in class b. but what i expected is, it should give null object error. but no error? can anybody help me in understanding this.
and if I use virtual for method of a, then i am getting null object error as i expected. for a1.display();
The reason the virtual method fails is because the simulator needs to lookup the actual object instance type to know which method to call, and the object is null.
Accessing non-static members (see 8.9) or virtual methods (see 8.20) via a null object handle is illegal. The result of an illegal access via a null object is indeterminate, and implementations may issue an error.
In the above example, display() functions in both Class A & B are non-static members. According to the LRM, there should be an error. Can you please explain this?