Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Access Levels in Visual Basic
In this articleThe access level of a declared element is the extent of the ability to access it, that is, what code has permission to read it or write to it. This is determined not only by how you declare the element itself, but also by the access level of the element's container. Code that cannot access a containing element cannot access any of its contained elements, even those declared as PublicThe Public keyword in the declaration statement specifies that the element can be accessed from code anywhere in the same project, from other projects that reference the project, and from any assembly built from the project. The following code shows
a sample
You can use ProtectedThe Protected keyword in the
declaration statement specifies that the element can be accessed only from within the same class, or from a class derived from this class. The following code shows a sample
You can use FriendThe
Friend keyword in the declaration statement specifies that the element can be accessed from within the same assembly, but not from outside the assembly. The following code shows a sample
You can use Protected FriendThe Protected Friend keyword combination in the declaration statement specifies that the element can be accessed either from derived classes or from within the same assembly, or
both. The following code shows a sample
You can use PrivateThe
Private keyword in the declaration statement specifies that the element can be accessed only from within the same module, class, or structure. The following code shows a sample
You can use At the module level, the Private ProtectedThe
Private Protected keyword combination in the declaration statement specifies that the element can be accessed only from within the same class, as well as from derived classes found in the same assembly as the containing class. The The following example shows a
You can declare a The
To use the
For more information see setting the Visual Basic language version. Access ModifiersThe keywords that specify access level are called access modifiers. The following table compares the access modifiers:
See also
FeedbackSubmit and view feedback for Which access modifiers make variables and methods visible only in the class where they are declared?Private: The private access modifier is specified using the keyword private. The methods or data members declared as private are accessible only within the class in which they are declared.
Which access modifier makes variables and methods visible only in the class where they are declared private/public protected no explicit modifier?Private Access Modifier
They are accessible only within the class which has these private entities as its members.
Which access modifier makes variables and methods visible?Basic Access Modifiers
By default, the variables and methods of a class are accessible to members of the class itself and to other classes in the same package. To borrow from C++ terminology, classes in the same package are friendly. We'll call this the default level of visibility.
Which modifier is visible within the class only?Types of Access Modifier. |