C# - Interfaces Questions and Answers

Practice Mode
Showing 10 of 38 questions
Q21
Which of the following can implement an interface
  • A Class only
  • B Struct only
  • C Explanation: Both classes and structs can implement interfaces.
  • D Interface only
Answer: Option C
Explanation: Both classes and structs can implement interfaces.
Q22
What happens if a class does not implement all interface members
  • A Code compiles successfully
  • B Runtime error occurs
  • C Explanation: All interface members must be implemented, otherwise a compile-time error occurs.
  • D Interface methods are ignored
Answer: Option C
Explanation: All interface members must be implemented, otherwise a compile-time error occurs.
Q23
Which feature is mainly achieved using interfaces
  • A Encapsulation
  • B Explanation: Interfaces support polymorphism by allowing different implementations of the same contract.
  • C Data hiding
  • D Memory management
Answer: Option B
Explanation: Interfaces support polymorphism by allowing different implementations of the same contract.
Q24
Can an interface contain properties in C#
  • A No
  • B Yes, with implementation
  • C Explanation: Interfaces can declare properties but cannot implement them.
  • D Only static properties
Answer: Option C
Explanation: Interfaces can declare properties but cannot implement them.
Q25
Which version of C# introduced default interface methods
  • A C# 5.0
  • B C# 6.0
  • C C# 7.0
  • D Explanation: Default method implementations in interfaces were introduced in C# 8.0.
Answer: Option D
Explanation: Default method implementations in interfaces were introduced in C# 8.0.
Q26
What keyword is used to explicitly implement an interface member
  • A explicit
  • B override
  • C interface
  • D Explanation: Explicit interface implementation uses the interface name, not a keyword.
Answer: Option D
Explanation: Explicit interface implementation uses the interface name, not a keyword.
Q27
Why is explicit interface implementation used
  • A To improve performance
  • B Explanation: It is used to hide interface members from direct access through the class object.
  • C To create objects
  • D To avoid inheritance
Answer: Option B
Explanation: It is used to hide interface members from direct access through the class object.
Q28
Can an interface contain fields in C#
  • A Yes
  • B Explanation: Interfaces cannot contain fields.
  • C Only readonly fields
  • D Only static fields
Answer: Option B
Explanation: Interfaces cannot contain fields.
Q29
Which statement about interfaces is correct
  • A Interfaces can be instantiated
  • B Interfaces support constructors
  • C Explanation: Interfaces define a contract that implementing classes must follow.
  • D Interfaces store data
Answer: Option C
Explanation: Interfaces define a contract that implementing classes must follow.
Q30
How many interfaces can a class implement
  • A Only one
  • B Only two
  • C Explanation: A class can implement multiple interfaces.
  • D None
Answer: Option C
Explanation: A class can implement multiple interfaces.
Questions and Answers for Competitive Exams Various Entrance Test