MCQs on Procedures and Functions | Visual Basic .NET (VB.NET)

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

  1. 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
  2. What is the correct declaration for a sub-procedure?
    a) Sub MySub()
    b) Function MySub()
    c) Public Procedure()
    d) SubProc()
  3. 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
  4. In VB.NET, sub-procedures are invoked using:
    a) Execute
    b) Call
    c) Invoke
    d) Run
  5. 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

  1. 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
  2. What is the correct syntax to define a function?
    a) Sub MyFunction()
    b) Function MyFunction() As Integer
    c) Procedure MyFunction()
    d) Func MyFunction()
  3. 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
  4. 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
  5. 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)

  1. 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
  2. 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
  3. Which keyword is used to pass a variable by reference?
    a) Val
    b) ByRef
    c) Reference
    d) Pointer
  4. What is the default way of passing arguments in VB.NET?
    a) ByRef
    b) ByVal
    c) ByDefault
    d) ByArgs
  5. 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

  1. 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
  2. What must differ in overloaded functions?
    a) The name
    b) The parameter list
    c) The return type
    d) The access modifier
  3. 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
  4. Overloading improves:
    a) Code readability and reusability
    b) Application performance
    c) Security
    d) Debugging complexity
  5. Which keyword enables function overloading in VB.NET?
    a) Overload
    b) Overridable
    c) New
    d) None of the above

Mixed Concepts

  1. Which access modifier can be used for both functions and sub-procedures?
    a) Private
    b) Public
    c) Friend
    d) All of the above
  2. A sub-procedure can:
    a) Call another sub-procedure
    b) Call a function
    c) Both a and b
    d) Only call itself
  3. 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
  4. Overloading functions leads to:
    a) Compilation errors
    b) Clarity in code
    c) Ambiguity in execution
    d) Poor performance
  5. 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

  1. 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
  2. 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
  3. A function can return multiple values using:
    a) ByRef parameters
    b) Arrays
    c) Tuples
    d) All of the above
  4. 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
  5. Overloading is also referred to as:
    a) Function overriding
    b) Polymorphism
    c) Encapsulation
    d) Abstraction

Answers

QnoAnswer
1b) Can be called without arguments
2a) Sub MySub()
3c) They do not return a value
4b) Call
5b) It will never execute
6b) Return a value
7b) Function MyFunction() As Integer
8b) They can have parameters
9b) Functions return a value, while sub-procedures do not
10a) Return value
11b) The value cannot be modified
12a) Passing a reference to the variable, allowing modification
13b) ByRef
14b) ByVal
15a) Affect the original variable
16a) Defining multiple functions with the same name but different signatures
17b) The parameter list
18a) Yes, if the parameter types are different
19a) Code readability and reusability
20d) None of the above
21d) All of the above
22c) Both a and b
23b) Accessible within its class only
24b) Clarity in code
25a) The procedure needs to modify the original variable
26a) Function Add(x As Integer) As Integer and Function Add(x As String) As String
27b) Both can take parameters
28d) All of the above
29b) Ends a function and returns a value
30b) Polymorphism

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top