C# - Functions and Subroutines Questions and Answers

Practice Mode
Showing 10 of 29 questions
Q21
Which type of method can be called without creating an instance of the class?
  • A Instance methods
  • B Static methods
  • C Virtual methods
  • D Abstract methods
Answer: Option B
Explanation: Static methods belong to the class rather than instances.
Q22
What is the difference between a function and a subroutine in C#?
  • A Functions return values, subroutines do not
  • B Subroutines return values, functions do not
  • C There is no difference in C#
  • D Functions are faster than subroutines
Answer: Option A
Explanation: In C#, all methods are essentially functions; void methods don't return values.
Q23
Which of the following is true about void methods?
  • A They must return a value
  • B They can return multiple values
  • C They do not return any value
  • D They can only be used in static classes
Answer: Option C
Explanation: Void methods perform actions but don't return values.
Q24
What is the purpose of method parameters with default values?
  • A To make parameters constant
  • B To allow calling methods without providing all arguments
  • C To increase method performance
  • D To hide parameters from other methods
Answer: Option B
Explanation: Default parameters allow calling methods without providing all arguments.
Q25
Which keyword is used to pass parameters by reference in C#?
  • A out
  • B ref
  • C param
  • D byref
Answer: Option B
Explanation: ref keyword passes variables by reference rather than by value.
Q26
What happens if a non-void method doesn't have a return statement?
  • A It returns null automatically
  • B It causes runtime error
  • C It causes compilation error
  • D It returns default value
Answer: Option C
Explanation: Non-void methods must return a value of the specified type.
Q27
Which of the following describes a static method?
  • A Called using object instances
  • B Can access instance variables directly
  • C Called using class name without creating instances
  • D Cannot be called from other methods
Answer: Option C
Explanation: Static methods are called using the class name and don't require instances.
Q28
What is the scope of variables declared inside a method?
  • A Global scope
  • B Class scope
  • C Method scope only
  • D Project scope
Answer: Option C
Explanation: Local variables are only accessible within the method they are declared.
Q29
Which of the following is an advantage of using methods?
  • A Makes code longer
  • B Increases code duplication
  • C Promotes code reusability
  • D Makes debugging harder
Answer: Option C
Explanation: Methods promote code reusability and better organization.
Questions and Answers for Competitive Exams Various Entrance Test