Function new() overriding ? why should we call super.new() function in derived class constructor?

In your example, you are trying to construct two objects - an A object with class member x, and a B object with class members x and p.

When you construct the A object with a_o = new(1), its member x will be set to 1.

When you construct the B object with b_0 = new(100), the constructor first calls the super.new(400) constructor and x will be set to 400. When it returns p will be set to 100.

So at the end of your initial block, you will have two objects: an A object with member x set to 1, and a B object with members x set to 400 and member p set to 100.

If you comment out the call to super.new(400) in B’s constructor, SystemVerilog will insert a call to super.new() with no arguments for you. Since A constructor requires 1 argument, that implicit call to new() is giving you a compiler error (It is always a good idea to show the error message so we don’t have to guess).

To fix the error, you need to do of three things.

  1. put the call to super.new(400) back.
  2. provide a default value for a in A’s constructor
  3. remove the argument to A’s constructor