Home » mcq » Visual basic » when we declare the variable in . . . . . . . . of VB then it is public variable
static
public
local
general
Answer is Right!
Answer is Wrong!
The correct answer is: C. local
A local variable is a variable that is declared inside a procedure or function. It is only accessible
288 64 288 64S117.2 64 74.6 75.5c-23.5 6.3-42 24.9-48.3 48.6-11.4 42.9-11.4 132.3-11.4 132.3s0 89.4 11.4 132.3c6.3 23.7 24.8 41.5 48.3 47.8C117.2 448 288 448 288 448s170.8 0 213.4-11.5c23.5-6.3 42-24.2 48.3-47.8 11.4-42.9 11.4-132.3 11.4-132.3s0-89.4-11.4-132.3zm-317.5 213.5V175.2l142.7 81.2-142.7 81.2z"/>
Subscribe on YouTube
within that procedure or function.
A static variable is a variable that is declared outside of any procedures or functions. It is accessible from all procedures and functions in the class.
A public variable is a variable that is declared with the Public keyword. It is accessible from all procedures and functions in all classes in the project.
A general variable is not a valid option.
Here is an example of a local variable:
Sub MySub()
Dim x As Integer
x = 10
End Sub
In this example, the variable x is declared inside the procedure MySub. It is only accessible from within MySub.
Here is an example of a static variable:
“`
Class MyClass
Private x As Integer
Public Sub MySub()
x = 10
End Sub
End Class
“`
In this example, the variable x is declared outside of any procedures or functions. It is accessible from all procedures and functions in the class MyClass.
Here is an example of a public variable:
Public x As Integer
In this example, the variable x is declared with the Public keyword. It is accessible from all procedures and functions in all classes in the project.