Friday, May 31, 2013

Private Access Modifiers

This is the most restrictive access modifier, any member of the class which is defined private cannot be accessed from outside the class, these members are visible only within the class, trying to access these members outside the class will result in a compilation error.

The following example defines a private variable
strPrivateName.

    class BaseClass
    {
        private string strPrivateName;
        public string strPublicName;
        protected string strProtectedName;
        internal string strInternalName;
        protected internal string strProtectedInternalName;
    }
    //
    class ChildClass : BaseClass
    {
        public string strChildName;
    }

Notice that the private variable is not visible to the object of the class, which is instantiated in an external class. 




Search Flipkart Products:
Flipkart.com

No comments: