Explain the concept of a constructor in SystemVerilog.
Explain the concept of a constructor in SystemVerilog.
Model answer
A constructor is a special method, always named new , that creates an object and initializes its members. It runs when new() is called, not when a handle is declared. It is declared with function new(...) and has no return type. A class has only one constructor, so it cannot be overloaded. Default argument values give similar flexibility. Declaring one is optional. If it is omitted, an implicit new() is provided. It cannot be declared virtual or static. It is not inherited. In a derived class, it starts by calling super.new().