Object creation

In reply to jaswanth_b:

It would help to explain what you intend to mean by “outside” a task. A simple example of what you were thinking of would work too.

You can construct an object anywhere you can declare a class variable as part of its initial value. And you can construct a object anywhere you can make an assignment to a class variable.

Please see A Short Class on SystemVerilog Classes - Verification Horizons for more on the terminology I am using.

The UVM recommends creating objects in the build_phase rather than the component’s constructor new() because it makes overriding easier. You cannot override the code in a constructer new().