HELP ME WITH THIS CODE

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:

KERNEL: – Pakistan –

KERNEL: Countries in world =

KERNEL: Lahore

KERNEL: Rawalpindi

KERNEL: Pakpattan

KERNEL: – INDIA –

KERNEL: Countries in world =

KERNEL: Mumbai

KERNEL: Valsad

KERNEL: Dholakpur

KERNEL: Simulation has finished. There are no more test vectors to simulate.

In reply to Muneeb Ur Rehman:

Please use code tags to make your code easier to read.

The only place in your code where the “get_pop” is called is the “state” function.
The “state” function is not called anywhere. That’s why the pop value is not getting displayed.

You can either call the “state” function in your code, or you can add the get_pop to your “list_world” function as below :

  
  function void list_world();
    $display("Countries in world = ");
    foreach (world[i]) begin
      $display(world[i].get_name());
      $display(world[i].get_pop());
    end
  endfunction : list_world