-1
class AAA;

  rand int a;
  rand bit b;

  constraint aaa;

  class BBB extends AAA ;

    constraint aaa {a>4 && a<67 ; b>10 && b<90 ;}

  endclass
endclass

module mode;

  AAA p;
  AAA::BBB q;

  initial begin
    p=new;
    q=new;
    repeat(10)
      begin
        assert(p.randomize());

        $display("%0d , %0d",q.a,q.b);
      end


  end

endmodule
Matthew Taylor
  • 13,365
  • 3
  • 17
  • 44

1 Answers1

0

You are mixing up inheritance (IS-A) with containers (HAS-A) and nested declarations. With inheritance, you just construct the extended class. If you construct the base class, that object has no knowledge of any extensions to it, including classes with nested class declarations.

There's no reason to use nested classes unless you need to hide the name of the nested class type from the general name space. Otherwise, a nested class behaves identically as if you had declared it without nesting it.

dave_59
  • 39,096
  • 3
  • 24
  • 63