Extending from parameterized classes and using base classes pointers

I found this question on a interview prep website. I think the reason a1 = b1 is not allowed is because derived class b uses different parameters but I don’t know how to solve it. Is $cast the way to go?

In the below example,"a1 = b1"is not allowed. Why is it not allowed and what is the solution ?

class a#(type T=int); 
   virtual function void func1(); 
      $display("Inside base"); 
   endfunction :func1 
endclass 

class b extends a#(real); 
   virtual function void func1(); 
      $display("Inside derived"); 
   endfunction :func1 
endclass 

module top; 
   a a1;  
   b b1=new(); 

   initial begin 
      a1 = b1; 
      a1.func1(); 
   end 
endmodule:top

In reply to Pooja Pathak:

Because class A is parameterized class, “parameterized” means constant
A’s default type is “int” and class b is a derived class of a#(T=“real”).
So it’s not compatible. “a1 = b1”, this downcasting doesn’t work.
if you change in this way, then it becomes compatible again.

class b extends a#(int); 
class b extends a;

In reply to javatea:

Your solution makes b type compatible a#(int), but now no longer uses the real type, which may need to be preserved. Hint, find a way to add a common base class.