C# - Interfaces Questions and Answers

Practice Mode
Showing 10 of 38 questions
Q31
Which of the following cannot be declared in an interface
  • A Events
  • B Indexers
  • C Constants
  • D Explanation: Interfaces cannot contain instance variables.
Answer: Option D
Explanation: Interfaces cannot contain instance variables.
Q32
Can interfaces be used for dependency injection
  • A No
  • B Explanation: Interfaces are commonly used in dependency injection to reduce tight coupling.
  • C Only with structs
  • D Only with abstract classes
Answer: Option B
Explanation: Interfaces are commonly used in dependency injection to reduce tight coupling.
Q33
What symbol separates multiple interfaces in implementation
  • A Explanation: Multiple interfaces are separated using commas.
  • B Semicolon
  • C Dot
  • D Pipe
Answer: Option A
Explanation: Multiple interfaces are separated using commas.
Q34
Can an interface extend multiple interfaces
  • A No
  • B Explanation: An interface can inherit multiple interfaces.
  • C Only two interfaces
  • D Only abstract interfaces
Answer: Option B
Explanation: An interface can inherit multiple interfaces.
Q35
Which access modifier is not allowed in interface members
  • A public
  • B Explanation: Interface members cannot be private.
  • C protected
  • D internal
Answer: Option B
Explanation: Interface members cannot be private.
Q36
What is the main difference between interface and abstract class
  • A Interface supports constructors
  • B Abstract class supports multiple inheritance
  • C Explanation: Interfaces support multiple inheritance, whereas abstract classes do not.
  • D Abstract class cannot have methods
Answer: Option C
Explanation: Interfaces support multiple inheritance, whereas abstract classes do not.
Q37
Can an interface contain static methods
  • A No
  • B Explanation: Static methods in interfaces are allowed starting from C# 8.0.
  • C Only in classes
  • D Only in structs
Answer: Option B
Explanation: Static methods in interfaces are allowed starting from C# 8.0.
Q38
When should an interface be preferred over an abstract class
  • A When common code is required
  • B Explanation: Interfaces are preferred when multiple inheritance is required.
  • C When data members are needed
  • D When constructors are required
Answer: Option B
Explanation: Interfaces are preferred when multiple inheritance is required.
Questions and Answers for Competitive Exams Various Entrance Test