Casting

class B; 
virtual 
  task print(); 
$display(" CLASS B "); 
endtask 
endclass 

class E_1 extends B; 
virtual 
  task print(); 
$display(" CLASS E_1 "); 
endtask 
endclass 

class E_2 extends B; 
virtual
  task print(); 
$display(" CLASS E_2 "); 
endtask 
endclass 

module main; 
initial 
begin 
 B b; 
E_1 e1; 
E_2 e2; 

  e1 = new(); 
  $cast(e2,e1); 
  
end 
endmodule

Casting of source class type ‘E_1’ to destination class type ‘E_2’ failed
due to type mismatch.
Please ensure matching types for dynamic cast

Can anyone please explain clearly

In reply to suresh M:

Do you know the reason you need to use $cast? and when it would succeed or fail?

In reply to dave_59:

i read it but I don’t understand the reason.

please explain it