SV: class assignemnt (part A) - 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


37
 
1
// Code your testbench here
2
// or browse Examples
3
class parent_trans;
4
  bit [31:0] data;
5
  int id;
6
  
7
  function void display();
8
    $display("Base: Value of data = %0d, id = %0d", data, id);
9
  endfunction
10
endclass
11
12
class child_trans extends parent_trans;
13
  bit [31:0] data;
14
  int id;
15
  
16
  function void display();
17
    $display("Child: Value of data = %0d, id = %0d", data, id);
18
  endfunction
19
endclass
20
21
module class_example;
22
  initial begin
23
    parent_trans p_tr;
24
    child_trans c_tr;
25
    c_tr = new();
26
      
27
    p_tr = c_tr;
28
    
29
    p_tr.data = 10;
30
    p_tr.id   = 1;
31
    
32
    c_tr.data = 5;
33
    c_tr.id   = 2;
34
    
35
    p_tr.display();
36
  end
37
endmodule
xxxxxxxxxx
1
 
1
// Code your design here
2
1039 views and 0 likes     
 
Example for class assignemnt (part A): Both base and child classes have same name of properties.

Example for class assignemnt (part A): Both base and child classes have same name of properties.

1160:0