Reputation: 3
The output of the below code was-
This is class A
This is class A
But according to me the output should be-
This is class A
This is Extended class A
Because, after printing the first line, we are assigning object of type EA to object of type A-
EA my_a = my_ea;
and then when we do- my_a.disp();
it should print-This is Extended class A
Please tell whether I am correct or not?
class A ; //class A
task disp ();
$display(" This is class A ");
endtask
endclass
class EA extends A ; //subclass EA
task disp ();
$display(" This is Extended class A ");
endtask
endclass
program main ;
EA my_ea;
A my_a;
initial
begin
my_a = new();
my_a.disp();
my_ea = new();
my_a = my_ea;
my_a.disp();
end
endprogram
Upvotes: 0
Views: 194
Reputation: 898
You need to declare the task as virtual:
class A ; //class A
virtual task disp ();
$display(" This is class A ");
endtask
endclass
Upvotes: 3