SV Verification Directory

Encapsulation

Encapsulation is a technique used to restrict access to the data and methods within a class, ensuring that internal class details are not accessible from outside the class.

Access Specifiers

These define the visibility of class members and they are as follows:

Local

Members declared as local are accessible only within the class itself.

  • Syntax

    class ex;
       local int a;
    
       function new();
          // execute code
       endfunction
    
    endclass
    

Protected

Members declared as protected are accessible within the class and its derived classes.

  • Syntax

    class ex;
       protected int a;
    
       function new();
          // execute code
       endfunction
    
    endclass
    

Public

Members declared as public are accessible from anywhere.

  • Syntax

    class ex;
       public int a;
    
       function new();
          // execute code
       endfunction
    
    endclass
    

Note: By default, all properties and methods of a class in SystemVerilog are public and can be accessed from anywhere using the object handle.