|
|
1 program class_super;
2
3 class A ;
4 integer j;
5 function new();
6 begin
7 j = 10;
8 end
9 endfunction
10 task print();
11 begin
12 $display("j is %0d",j);
13 end
14 endtask
15 endclass
16
17 class B extends A;
18 integer i = 1;
19 function new();
20 begin
21 // call the parent new
22 super.new(); // constructor chaining
23 $display("Done calling the parent new");
24 i = 100;
25 end
26 endfunction
27 // Override the parent class print
28 task print();
29 begin
30 $display("i is %0d",i);
31 $display("Call the parent print");
32 super.print();
33 end
34 endtask
35 endclass
36
37 initial begin
38 B b1;
39 b1 = new;
40 b1.print();
41 end
42
43 endprogram
You could download file class_super.sv here
|