Skip to content
asicguru.tech@gmail.com
REGISTER LOGIN
AsicGuru Ventures
  • All Courses
  • CONTACT
  • GALLERY
  • HOME
  • Tutorials

0

Verilog Tutorial

17
  • Introduction
  • Lexical Tokens
  • Gate-Level Modelling
  • Data Types
  • Operators
  • Operands
  • Modules
  • Behavioral Modeling
  • Timing Controls
  • Procedures: Always and Initial Blocks
  • Functions
  • Tasks
  • Component Inference
  • Finite State Machines.
  • Compiler Directives
  • System Tasks and Functions
  • Test Benches

System Verilog

23
  • System Verilog Introduction
  • Data Types
  • Type Casting
  • Arrays
  • Associative Arrays
  • Dynamic Arrays
  • Queue
  • Operators
  • Procedural statements and Control flow
  • Classes
  • Inheritance
  • Encapsulation
  • This and Super operator
  • In-Line Constraints
  • Class Constraints
  • Virtual Classes
  • Parameterized Classes
  • Classes Summary
  • Singleton Classes
  • Functional Coverage Introduction
  • Covergroup
  • Tools
  • Books

Scripting

15
  • Introduction
  • Perl Tutorial
  • What is Perl
  • Perl: Syntax And Variable
  • Perl Strings
  • Perl Arrays
  • Perl Associative Arrays
  • If/While Syntax
  • File Input
  • Print Output
  • String Processing with Regular Expressions
  • Subroutines
  • Running External Programs
  • References
  • Terse Perl

Makefile

1
  • Makefile Tutorial

Interview Questions

2
  • SystemVerilog Interview Questions
  • Verilog Interview Questions

Handwritten Notes

3
  • Perl (Scripting)
  • Linting
  • CMOS Logic Design
View Categories
  • Home
  • Tutorials
  • System Verilog
  • Encapsulation

Encapsulation

1 min read

What is Encapsulation? #

Encapsulation is an object-oriented programming concept where internal class details (properties and methods) are hidden from outside access. It promotes data protection, modularity, and controlled access to sensitive parts of a class.

Access Control in SystemVerilog Classes #

In SystemVerilog, class properties are public by default — meaning they can be accessed directly using the dot (.) operator from outside the class.

To restrict access, SystemVerilog provides two access modifiers:

ModifierAccessible FromDescription
localOnly within the same classHides data completely from outside and child classes
protectedSame class and subclassesAllows access in child classes, but not from the testbench or other modules

Access Control Summary

ModifierSame ClassSubclassOutside Class
1. Public (default)✅✅✅
2. Protected✅✅❌
3. Local✅❌❌

1.Public : Members are accessible from outside (default in SystemVerilog).

class Packet;
  int id;             // Can be accessed from outside
 function void display();
  $display("ID = %0d", id);
 endfunction
endclass

module tb;
 initial begin
  Packet pkt = new();
  pkt.id = 5;         // Accessing public variable
  pkt.display();  
 end
endmodule

2.Protected : Members are accessible in the class and its subclasses only.

class Base;
  protected int id = 42;
 function void display();
  $display("Base ID = %0d", id);
 endfunction
endclass

class Derived extends Base;
 function void show_id();
  $display("Derived accessing ID = %0d", id);   //Allowed
 endfunction
endclass

module tb;
 initial begin
  Derived d = new();
  d.show_id();       //Works
  // d.id = 10;      //Error: 'id' is protected 
 end
endmodule

3.Private: Class data members and methods are accessible only inside the class where it is defined and not accessible from outside the class or in derived classes.

class A;
  private int x = 42;
 function void show();
  $display("x = %0d", x);    //Allowed
 endfunction
endclass

class B extends A;
 function void try_access();
  $display("x = %0d", x);    //Error: private member not accessible
 endfunction
endclass
Updated on August 2, 2025

What are your Feelings

  • Happy
  • Normal
  • Sad
Share This Article :
  • Facebook
  • X
  • LinkedIn
  • Pinterest
InheritanceThis and Super operator

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Table of Contents
  • What is Encapsulation?
  • Access Control in SystemVerilog Classes

Archives

  • May 2025

Categories

  • Slider Post
  • Uncategorized

Copyright @ Asicguru Ventures by Misbah WP | Proudly powered by WordPress