C# - Interfaces Questions and Answers

Practice Mode
Showing 10 of 38 questions
Q11
Which of the following can implement an interface?     Data     Class     Enum     Structure     Namespace
  • A 1, 3
  • B 2, 4
  • C 3, 5
  • D 4 only
Answer: Option B
Q12
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     } }
  • A Class MyClass is an abstract class.
  • B Class MyClass cannot contain instance data.
  • C Class MyClass fully implements the interface IMyInterface.
  • D Interface IMyInterface should be inherited from the Object class.
Answer: Option
Q13
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(); }
  • A Properties cannot be declared inside an interface.
  • B This is a perfectly workable interface.
  • C The properties in the interface must have a body.
  • D Subroutine in the interface must have a body.
Answer: Option B
Q14
What is the primary purpose of an interface in C#
  • A To provide method implementation
  • B Explanation: Interfaces allow a class to implement multiple behaviors, supporting multiple inheritance.
  • C To store data members
  • D To create objects directly
Answer: Option B
Explanation: Interfaces allow a class to implement multiple behaviors, supporting multiple inheritance.
Q15
Which keyword is used to define an interface in C#
  • A class
  • B struct
  • C Explanation: The interface keyword is specifically used to declare an interface.
  • D abstract
Answer: Option C
Explanation: The interface keyword is specifically used to declare an interface.
Q16
Which member is allowed inside a C# interface
  • A Instance fields
  • B Constructors
  • C Explanation: Interfaces can only declare methods, properties, events, and indexers without implementation.
  • D Static variables with values
Answer: Option C
Explanation: Interfaces can only declare methods, properties, events, and indexers without implementation.
Q17
By default, members of an interface are
  • A private
  • B protected
  • C internal
  • D Explanation: All interface members are public by default and cannot use access modifiers.
Answer: Option D
Explanation: All interface members are public by default and cannot use access modifiers.
Q18
Which of the following is true about interface methods
  • A They can have method bodies
  • B They must be static
  • C Explanation: A class implementing an interface must provide implementations for all its members.
  • D They can be private
Answer: Option C
Explanation: A class implementing an interface must provide implementations for all its members.
Q19
How does a class implement an interface
  • A Using the inherits keyword
  • B Using the implements keyword
  • C Explanation: A class implements an interface using the colon : symbol.
  • D Using the override keyword
Answer: Option C
Explanation: A class implements an interface using the colon : symbol.
Q20
Can an interface inherit another interface in C#
  • A Explanation: Interfaces can inherit one or more interfaces.
  • B No
  • C Only with abstract keyword
  • D Only one interface can be inherited
Answer: Option A
Explanation: Interfaces can inherit one or more interfaces.
Questions and Answers for Competitive Exams Various Entrance Test