Friday, May 31, 2013

Public Access Modifiers

This is the most lenient of all the access modifier, any member of the class which is defined public can be accessed from anywhere inside or outside of the class. Members defined with this modifier provide no restriction in getting or setting the values.

The following example defines a public variable
strPublicName.

    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 public variable is visible to the object of the class, which is instantiated in an external class. 



Search Flipkart Products:
Flipkart.com

No comments: