---
title: "What is Encapsulation?"  
description: "What is Encapsulation?"  
author: "Shikhar Arora"  
published: 2019-11-07  
updated: 2019-11-07  
canonical: https://www.mindstick.com/forum/145450/what-is-encapsulation  
category: "c#"  
tags: ["c#", ".net", "oops", "programming language"]  
reading_time: 2 minutes  

---

# What is Encapsulation?

What is [Encapsulation](https://www.mindstick.com/articles/12229/encapsulation-and-access-specifier) C#?

## Replies

### Reply by Shikhar Arora

Encapsulation is grouping the related methods, variables, and properties in a single unit. It is used for protecting the objects and methods of one class from getting accessed by another class. In short, it is hiding the inner parts of the machine from the outside world.

```
namespace Encapsulation
{
 //Encapsulating the methods of Testers class.
    class Testers
    {
 //applying access modifiers on methods
        private void Print() //private access modifier applied
        {
            Console.WriteLine("Testing..");
        }
        protected void Test()//protected access modifier applied
        {
            Console.WriteLine("Test2..");
        }
        protected internal void Tester()//protected internal access modifier applied
        {
            Console.WriteLine("Test3..");
        }
    }
    class Program : Testers
    {
        static void Main(string[] args)
        {
            Program obj = new Program();	//Instantiating Program class
  //Trying to call methods of testers class
            //obj.Print();
            obj.Test();
            obj.Tester();
            Console.ReadLine();
        }
    }
}
```


---

Original Source: https://www.mindstick.com/forum/145450/what-is-encapsulation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
