VB.NET 1.1 Tutorial - Access Modifiers
An access-modifier determines what can be seen by another part of the program with reference to Properties and Methods.
| Access Modifier |
Restrictions |
| Public |
No restrictions. Properties and Methods marked Public are visible to any method of any class. |
| Private |
The Properties and Methods in class A which are marked Private are accessible only to methods of class A and cannot be accessed by derived classes or other classes. |
| Protected |
The Properties and Methods in class A which are marked Protected are accessible to methods of class A and also to methods of classes derived from class A. |
| Friend |
The Properties and Methods in class A which are marked Friend are accessible to methods of any class in A's assembly. |
| Protected Friend |
The Properties and Methods in class A which are marked Protected Friend are accessible to methods of class A, to methods of classes derived from class A, and also to any class in A's assembly. This is effectively Protected OR Friend (There is no concept of Protected AND Friend.) |
In general, the Properties of a class are designated as Private and the Methods that act upon the attributes are designated as Public.
You do not have to give a class an access modifier, it will default to Friend, because a class cannot be Private. However it is good practice to do so.
When declaring Properties or Methods, the default modifier is Private if no modifier is supplied.
References
For more information on the Class access modifiers, visit MSDN at microsoft here.
What Next?
Return to the Tutorial Contents.
|