A Simple Class Code (constructor related ) with three cases

CASE I : -

class  static_check;

    int  var1;     
    int i;
   task    do_something_for_static();

        for(i=0 ; i <10; i++)
        begin
           int var1 = i+1 ;
           $display("THE VALUE OF var1=%d",var1);
        end

   endtask 

endclass  


module static_var_check;
   static_check   statc_h;

   initial 
     begin
        statc_h =new();                                 HERE WE NEEDED TO CALL THE CONSTRUCTOR  
        statc_h.do_something_for_static();
     end

endmodule

CASE II : -

class  static_check;

   // int  var1;     
   // int i;
   task    do_something_for_static();

        for(int  i=0 ; i <10; i++)
        begin
           static int var1 = i+1 ;
           $display("THE VALUE OF var1=%d",var1);
        end

   endtask 

endclass  


module static_var_check;
   static_check   statc_h;

   initial 
     begin
       // statc_h =new();                          ///HERE WE DO NOT NEEDED TO CALL THE CONSTRUCTOR 
        statc_h.do_something_for_static();
     end

endmodule

CASE III : -

class  static_check;

   static int  var1;     
   static int i;
   task    do_something_for_static();

        for(i=0 ; i <10; i++)
        begin
           static int var1 = i+1 ;
           $display("THE VALUE OF var1=%d",var1);
        end

   endtask 

endclass  


module static_var_check;
   static_check   statc_h;

   initial 
     begin
       // statc_h =new();                          ///HERE AGAIN WE DO NOT NEEDED TO CALL THE CONSTRUCTOR 
        statc_h.do_something_for_static();
     end

endmodule

Can someone please help me understand this all three cases

In reply to pk_94:

See Why is my code not failing when accessing non static method from not static class? | Verification Academy

In reply to pk_94:

Classes are not ever static (always “dynamic”). You always have to call the constructor so that memory can be allocated. It’s not automatic.

In reply to Wes:

The LRM allows referencing static class members with a null handle. The compiler guarantees static methods will not reference any non-static class members. There is no such guarantee with a non-static method.

In reply to dave_59:

I see. Thanks Dave. So, correct me if I’m wrong, in

“CASE I” you have to use “new” because non-static member “i” is used in the task, in

“CASE II” no members were referenced, only task local variables, so this is legal, in

“CASE III” only static member “i” is referenced outside of the task, so “new” is not required.

In reply to Wes:

Correct for CASE I. See my link for CASES II and III.