Use this space to put some text. Update this text in HTML

468x60 banner ad

Advertise with Us

Powered by Blogger.
Showing posts with label encapsulation-in-c-sharp-with-example. Show all posts
Showing posts with label encapsulation-in-c-sharp-with-example. Show all posts

Tuesday, 16 February 2016

encapsulation-in-c-sharp-with-example


Encapsulation


1. We can combine both behavior and functionality both together with the wrapper of class. This means that a class which has data member as well as method is called encapsulation. 

      2. Dividing each of its classes into two distinct parts: the interface and the implementation.

      3. Class is the best example of encapsulation.



 By using the get and set methods (Accessors and Mutators) 
 
public class Account
{
    private string accoutName;
    
    // get methods
    public string GetAccount()
    {
        return accoutName;
    }
    // Set method
    public void SetAccount(string name)
    {
        accoutName = name;
    }
}
static void Main()
{
    string name ="SAVING_ACCOUNT";
    Account account = new Account();
    account.SetAccount(name);
    name = string.Empty;
    name = account.GetAccount();            
}