Encapsulation definition with example in C#.Net

Encapsulation definition with example

which is nothing but wrapping up of code and data. Here code is function and data is attributes. This approach will reduce the relationship between the objects as well give access to maintainability of the code.

Below table show how can we able to connectivity to the other objects.

This is one of the good OOPS DOTNET Interview Question.

Access ModifierDescription (access information)
privateOnly for with in the same type. These are default for all types (int, string,...)
protectedIf we use inheritence only derived types call access of base type
internalwe can accesses with in the assembly. 
protected internalthis is combination of protected and internal. 
publicwe can access any where. 

Example:
using System;

class BankAccountDetails
{
    private string m_CustName;

    public string bankCustName
    {
        get { return  m_CustName ; }
        set {  m_CustName  = value; }
    }
}


In this example. we are hiding the string bankCustName to the other object. 



See more OOPS DOTNET Interview Questions

See more ASP.NET, C#.NET, SQL Server and more Interview Questions


Share this post :

Featured post

JQuery Tutorial 1- Introduction to JQuery

If you have any queries or suggestions, please feel free to ask in comments section.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar