Share via


Protegido (Visual Basic)

Specifies that one or more declared programming elements are accessible only from within their own class or from a derived class.

Comentários

Sometimes a programming element declared in a class contains sensitive data or restricted code, and you want to limit access to the element. However, if the class is inheritable and you expect a hierarchy of derived classes, it might be necessary for these derived classes to access the data or code. In such a case, you want the element to be accessible both from the base class and from all derived classes. To limit access to an element in this manner, you can declare it with Protected.

Rules

  • Declaration Context. Você pode usar Protected somente no nível de classe . This means the declaration context for a Protected element must be a class, and cannot be a source file, namespace, interface, module, structure, or procedure.

  • Combined Modifiers. Você pode usar o Protected modificador juntamente com o Friend (Visual Basic) modificador na mesma declaração. This combination makes the declared elements accessible from anywhere in the same assembly, from their own class, and from derived classes. You can specify Protected Friend only on members of classes.

Behavior

  • Nível de acesso. All code in a class can access its elements. Code in any class that derives from a base class can access all the Protected elements of the base class. This is true for all generations of derivation. This means that a class can access Protected elements of the base class of the base class, and so on.

    Protected access is not a superset or subset of friend access.

  • Modificadores de acesso. The keywords that specify access level are called access modifiers. For a comparison of the access modifiers, see Níveis de acesso em Visual Basic.

The Protected modifier can be used in these contexts:

Class Statement

Const Statement

Declare Statement

Delegate Statement

Dim Statement

Enum Statement

Event Statement

Function Statement

Interface Statement

Property Statement

Structure Statement

Sub Statement

Consulte também

Referência

Público (Visual Basic)

Friend (Visual Basic)

Private (Visual Basic)

Conceitos

Níveis de acesso em Visual Basic

Procedimentos no Visual Basic

Outros recursos

Estruturas (Visual Basic)

Objetos e Classes no Visual Basic