Public keyword in visual basic

Specifies that one or more declared programming elements have no access restrictions.

If you are publishing a component or set of components, such as a class library, you usually want the programming elements to be accessible by any code that interoperates with your assembly. To confer such unlimited access on an element, you can declare it with Public.

Public access is the normal level for a programming element when you do not need to limit access to it. Note that the access level of an element declared within an interface, module, class, or structure defaults to Public if you do not declare it otherwise.


  • Declaration Context. You can use Public only at module, interface, or namespace level. This means the declaration context for a Public element must be a source file, namespace, interface, module, class, or structure, and cannot be a procedure.


  • Access Level. All code that can access a module, class, or structure can access its Public elements.
  • Default Access. Local variables inside a procedure default to public access, and you cannot use any access modifiers on them.
  • Access Modifiers. The keywords that specify access level are called access modifiers. For a comparison of the access modifiers, see Access Levels in Visual Basic.

The Public 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
  • Module Statement
  • Operator Statement
  • Property Statement
  • Structure Statement
  • Sub Statement

3 thoughts on “Public keyword in visual basic

  1. Pingback: Access Levels in Visual Basic | iiteeeestudents

  2. Pingback: Dim statement in visual basic | iiteeeestudents

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s