In the below code for the second child class (i.e, my_father) not able to access the parent class properties or method.
Could someone please help me. thank you.
typedef string house[3];/*house is a datatype of queue*/
typedef string vehicle[3];/*vehicle is a datatype of queue */
class my_grand_father;
integer cash;
vehicle cars;
house bungalows;
task add_properties(int money, vehicle car, house bungalow);
this.cash = money;
this.cars = {car};
foreach(bungalow[i])
bungalows[i] = bungalow[i];
endtask
task grand_father_properties_list();
$display ("grand_father had bank balance of %0d", this.cash);
$display ("grand_father had %0d bungalows.",$size(this.bungalows));
foreach(this.bungalows[i])
$display (this.bungalows[i]);
$display ("grand_father had %0d cars.", $size(this.cars));
foreach(cars[i])
$display (this.cars[i]);
endtask
endclass
class my_father extends my_grand_father;
task father_properties_list();
super.add_properties(super.cash, super.cars, super.bungalows);
$display ("father has bank balance of %0d", super.cash);
$display ("father has %0d bungalows.",$size(super.bungalows));
foreach(super.bungalows[i])
$display (super.bungalows[i]);
$display ("father has %0d cars.", $size(super.cars));
foreach(super.cars[i])
$display (super.cars[i]);
endtask
endclass
class i_am extends my_father;
task my_properties_list();
$display ("I'm inherited below properties.");
super.father_properties_list();
endtask
endclass
module inheritance;
my_grand_father grand_father;
my_father father;
i_am me;
string car[3];
string house[3];
initial begin
grand_father = new;
father = new();
me = new();
grand_father = father;
grand_father = me;
car = {"Swift dezire","audi a60","honda city"};
house = {"2bhk","3bhk","fram house"};
grand_father.add_properties (700000,car,house);
grand_father.grand_father_properties_list();
father.father_properties_list();
me.my_properties_list();
end
endmodule
output:
grand_father had bank balance of 700000
grand_father had 3 bungalows.
2bhk
3bhk
fram house
grand_father had 3 cars.
Swift dezire
audi a60
honda city
father has bank balance of 0
father has 3 bungalows.
father has 3 cars.
I’m inherited below properties.
father has bank balance of 700000
father has 3 bungalows.
2bhk
3bhk
fram house
father has 3 cars.
Swift dezire
audi a60
honda city