C# - Interfaces Questions and Answers

Take Exam

C# Interfaces programming questions and answers are frequently asked in technical interviews and placement exams conducted by top companies like Tech Mahindra, Infosys, and Wipro. Interfaces in C# define a contract that classes and structs can implement, ensuring consistency and abstraction in code design. Understanding interfaces helps programmers achieve loose coupling and multiple inheritance in an object-oriented way. Practicing programming interview questions with answers based on interfaces improves one’s ability to design modular, scalable software systems. Candidates should explore interface inheritance, explicit implementation, and default methods introduced in modern C# to excel in interview coding rounds.

Questions on interfaces and abstraction in C. Complement with C++ polymorphism and encapsulation
 

C# - Interfaces

Showing 10 of 38 questions

11. Which of the following can implement an interface?     Data     Class     Enum     Structure     Namespace

  • 1, 3
  • 2, 4
  • 3, 5
  • 4 only
Show Answer Report

12. Which of the following statements is correct about the C#.NET code snippet given below? interface IMyInterface {     void fun1();     void fun2(); } class MyClass: IMyInterface {     private int i;     void IMyInterface.fun1()     {         // Some code     } }

  • Class MyClass is an abstract class.
  • Class MyClass cannot contain instance data.
  • Class MyClass fully implements the interface IMyInterface.
  • Interface IMyInterface should be inherited from the Object class.
Show Answer Report

13. Which of the following statements is correct about the C#.NET code snippet given below? interface IPerson {     String FirstName     {         get;         set;     }     String LastName     {         get;         set;     }     void Print();     void Stock();     int Fun(); }

  • Properties cannot be declared inside an interface.
  • This is a perfectly workable interface.
  • The properties in the interface must have a body.
  • Subroutine in the interface must have a body.
Show Answer Report

14. What is the primary purpose of an interface in C#

  • To provide method implementation
  • Explanation: Interfaces allow a class to implement multiple behaviors, supporting multiple inheritance.
  • To store data members
  • To create objects directly
Show Answer Report

15. Which keyword is used to define an interface in C#

  • class
  • struct
  • Explanation: The interface keyword is specifically used to declare an interface.
  • abstract
Show Answer Report

16. Which member is allowed inside a C# interface

  • Instance fields
  • Constructors
  • Explanation: Interfaces can only declare methods, properties, events, and indexers without implementation.
  • Static variables with values
Show Answer Report

17. By default, members of an interface are

  • private
  • protected
  • internal
  • Explanation: All interface members are public by default and cannot use access modifiers.
Show Answer Report

18. Which of the following is true about interface methods

  • They can have method bodies
  • They must be static
  • Explanation: A class implementing an interface must provide implementations for all its members.
  • They can be private
Show Answer Report

19. How does a class implement an interface

  • Using the inherits keyword
  • Using the implements keyword
  • Explanation: A class implements an interface using the colon : symbol.
  • Using the override keyword
Show Answer Report

20. Can an interface inherit another interface in C#

  • Explanation: Interfaces can inherit one or more interfaces.
  • No
  • Only with abstract keyword
  • Only one interface can be inherited
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test