C# - Interfaces Questions and Answers
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
11. Which of the following can implement an interface? Data Class Enum Structure Namespace
- 1, 3
- 2, 4
- 3, 5
- 4 only
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.
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.