$cast.sv - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

205


32
 
1
class base_class;
2
  function void print();
3
            $display("calling from parent class");
4
  endfunction
5
endclass
6
7
class child extends base_class;
8
   function void print();
9
     $display("calling from child class");
10
  endfunction
11
endclass
12
  
13
module tb;
14
  base_class base_o;
15
  child ch1,ch2;  
16
    initial begin
17
      ch1=new();
18
      ch1.print();
19
      base_o=new();
20
      base_o = ch1;
21
      base_o.print();
22
      
23
      if($cast(ch2,base_o))begin
24
        $display("casting is successfull");
25
        ch2.print();
26
      end
27
         else
28
           $error("casting is unsuccessfull");
29
     
30
     
31
    end
32
endmodule    
xxxxxxxxxx
1
 
1
// Code your design here
2
36 views and 0 likes     
A short description will be helpful for you to remember your playground's details
 
100:0