So I made this code. In which i was supposed to get both pop and name as output but i’m only getting name at output. Please Help in this regards
virtual class country;
protected string name;
protected int pop = -1;
function new(int p, string n);
name = n;
pop = p;
endfunction : new
function string get_name();
return name;
endfunction : get_name
function int get_pop();
return pop;
endfunction : get_pop
pure virtual function void state();
endclass : country
class pakistan extends country;
protected string name;
function new(string name, int pop);
super.new(.n(name), .p(pop));
endfunction : new
function void state();
$display ("The name of country is = %s", get_name(),"And it's population is = %0d ", get_pop());
endfunction : state
endclass : pakistan
class india extends country;
function new(string name, int pop);
super.new(.n(name), .p(pop));
endfunction : new
function void state();
$display ("The name of country is = %s", get_name());
$display("And it's population is = %0d. ", get_pop());
endfunction : state
endclass : india
class sub_cont #(type F);
protected F world[$];
function void world_1(F f);
world.push_back(f);
endfunction : world_1
function void list_world();
$display("Countries in world = ");
foreach (world[i])
$display(world[i].get_name());
endfunction : list_world
endclass : sub_cont
module top ;
pakistan pakistan_h;
india india_h;
sub_cont # (pakistan) pakistan_world;
sub_cont # (india) india_world;
initial begin
pakistan_world = new();
pakistan_h = new("Lahore", 2300000);
pakistan_world.world_1(pakistan_h);
pakistan_h = new("Rawalpindi", 200000);
pakistan_world.world_1(pakistan_h);
pakistan_h = new("Pakpattan", 20000);
pakistan_world.world_1(pakistan_h);
india_world = new();
india_h = new("Mumbai", 23000000);
india_world.world_1(india_h);
india_h = new("Valsad", 200000);
india_world.world_1(india_h);
india_h = new("Dholakpur", 23000);
india_world.world_1(india_h);
$display("-- Pakistan --");
pakistan_world.list_world();
$display("-- INDIA --");
india_world.list_world();
end
endmodule : top
RESULT IS AS SHOWN: