Explore 30 carefully designed MCQs covering VB.NET procedures and functions. Test your understanding of sub-procedures, parameterized functions, argument passing methods, and function overloading to strengthen your VB.NET skills.
Procedures and Functions
Sub Procedures
A sub-procedure in VB.NET: a) Must return a value b) Can be called without arguments c) Is declared with the keyword Function d) Is mandatory to call
What is the correct declaration for a sub-procedure? a) Sub MySub() b) Function MySub() c) Public Procedure() d) SubProc()
Which of the following is true about sub-procedures? a) They cannot have parameters b) They must be private c) They do not return a value d) They are always called automatically
In VB.NET, sub-procedures are invoked using: a) Execute b) Call c) Invoke d) Run
What happens if a sub-procedure is not called? a) It executes automatically b) It will never execute c) It generates an error d) It is converted to a function
Functions with Parameters and Return Values
A function in VB.NET must: a) Have at least one parameter b) Return a value c) Be called with Sub d) Have no parameters
What is the correct syntax to define a function? a) Sub MyFunction() b) Function MyFunction() As Integer c) Procedure MyFunction() d) Func MyFunction()
Which of the following is true about functions? a) They must return a Boolean value b) They can have parameters c) They cannot have return values d) They are only used for arithmetic
What is the primary difference between a sub-procedure and a function? a) Functions can be private, but sub-procedures cannot b) Functions return a value, while sub-procedures do not c) Functions cannot have parameters d) Sub-procedures are faster than functions
How do you return a value from a function? a) Return value b) Exit Function value c) Output value d) End value
Passing Arguments (ByVal, ByRef)
What does passing an argument ByVal mean? a) The value can be modified in the calling method b) The value cannot be modified c) The reference is passed to the method d) The method must return a value
ByRef allows: a) Passing a reference to the variable, allowing modification b) Passing the value without modification c) Passing only integers d) Making the variable read-only
Which keyword is used to pass a variable by reference? a) Val b) ByRef c) Reference d) Pointer
What is the default way of passing arguments in VB.NET? a) ByRef b) ByVal c) ByDefault d) ByArgs
If a variable is passed ByRef to a procedure, changes made: a) Affect the original variable b) Are local to the procedure c) Cause an error d) Are ignored
Overloading Functions
Function overloading means: a) Defining multiple functions with the same name but different signatures b) Writing redundant code c) Using only one function name for all procedures d) Avoiding function parameters
What must differ in overloaded functions? a) The name b) The parameter list c) The return type d) The access modifier
Can overloaded functions have the same number of parameters? a) Yes, if the parameter types are different b) No, the count must differ c) Yes, if the return type is different d) No, the signature must be identical
Overloading improves: a) Code readability and reusability b) Application performance c) Security d) Debugging complexity
Which keyword enables function overloading in VB.NET? a) Overload b) Overridable c) New d) None of the above
Mixed Concepts
Which access modifier can be used for both functions and sub-procedures? a) Private b) Public c) Friend d) All of the above
A sub-procedure can: a) Call another sub-procedure b) Call a function c) Both a and b d) Only call itself
What is the scope of a private sub-procedure? a) Accessible within the entire project b) Accessible within its class only c) Accessible only to public methods d) Accessible by subclasses
Overloading functions leads to: a) Compilation errors b) Clarity in code c) Ambiguity in execution d) Poor performance
Passing arguments ByRef is useful when: a) The procedure needs to modify the original variable b) No modification is required c) The variable is a constant d) The procedure is private
Advanced Questions
Which function signature is valid for overloading? a) Function Add(x As Integer) As Integer and Function Add(x As String) As String b) Function Add(x As Integer) As Integer and Function Add(x As Integer) As Integer c) Function Add(x As Integer) As Integer and Sub Add(x As Integer) d) None of the above
Which statement about sub-procedures and functions is true? a) Only functions can take parameters b) Both can take parameters c) Functions cannot return values d) Sub-procedures can only be public
A function can return multiple values using: a) ByRef parameters b) Arrays c) Tuples d) All of the above
The keyword Return in VB.NET: a) Ends a procedure b) Ends a function and returns a value c) Declares a function return type d) Has no special meaning
Overloading is also referred to as: a) Function overriding b) Polymorphism c) Encapsulation d) Abstraction
Answers
Qno
Answer
1
b) Can be called without arguments
2
a) Sub MySub()
3
c) They do not return a value
4
b) Call
5
b) It will never execute
6
b) Return a value
7
b) Function MyFunction() As Integer
8
b) They can have parameters
9
b) Functions return a value, while sub-procedures do not
10
a) Return value
11
b) The value cannot be modified
12
a) Passing a reference to the variable, allowing modification
13
b) ByRef
14
b) ByVal
15
a) Affect the original variable
16
a) Defining multiple functions with the same name but different signatures
17
b) The parameter list
18
a) Yes, if the parameter types are different
19
a) Code readability and reusability
20
d) None of the above
21
d) All of the above
22
c) Both a and b
23
b) Accessible within its class only
24
b) Clarity in code
25
a) The procedure needs to modify the original variable
26
a) Function Add(x As Integer) As Integer and Function Add(x As String) As String