There are five access specifiers in Visual Basic .NET defined as follows:
•Public – Applied at the class level and is the most common specifier. Public Classes are classes that are intended to be used by any consumer.
Public Class PubClass
•Protected – can only be applied to Nested Classes. Are only accessible within the class and within the child classes.
Public Class HasProtected
Protected Class ProtectedClass
•Friend – Are accessible only within the program in which they are defined. If you add the Friend access specifier to a class definition, instance of that class can only be created from within th same program.
Friend Class FriendClass
Public Shared Sub PublicMethod()
•Protected Friend – Represents a union of the Protected and Friend Specifiers. Protected class must be nested class, thus Protected Friend class must be nested too.
Public Class HasProtectedFriend
Protected Friend Class ProtectedFriend
Public Shared Sub Test()
•Private – Can only be applied to a nested class. A Private nested class represents implementation details of the class. When you have complex problem that requires more problem solving horsepower then simple methods can provided, defining a nested private class that implements the abstraction.
Public Class HasPrivate
Private Class PrivateClass
Asked In: Many Interviews |