SystemVerilog Classes Extern Methods

 Classes Extern Methods 

Definition of method can be written outside the body of class.
to do this, need to declare the method (Function/Task) with extern qualifier along with
          a.any qualifiers (local, protected or virtual)
          b.full argument list. 
with in the class body.

The extern qualifier indicates that the body of the method (its implementation) is to be found outside the class declaration.
before the method name, class name should be specified with class resolution operator to specify to which class the method corresponds to.


In the example below,
crating the object of virtual class gives an compilation error.

//class with extern function
class packet;
  bit [31:0] addr;
  bit [31:0] data;

  //function declaration - extern indicates out-of-body declaration
  extern virtual function void display();

//function implementation outside class body
function void packet::display();
  $display("Addr = %0d Data = %0d",addr,data);
module extern_method;
  initial begin
    packet p;
    p = new();
    p.addr = 10; = 20;

 Simulator Output  
Addr = 10 Data = 20
Execute the above code on