In reply to shobhana.swarnkar18:
obj is a class variable whose type is AB. obj.a is a class member variable whose type is int.If you declared the associative array with
int arr[AB], you want to the index to be a constructed object of
AB. The values of the class member variables are not relevant here.
initial
begin
obj = new();
obj.a = 5; // irrelevant
arr[obj]=20;
$display("%0d\n",arr[obj]); // should display 20
end