C# - Interfaces Question and Answer
C# - Interfaces Question and Answer
1. Which of the following statements is correct about the C#.NET code snippet given below?
interface IMyInterface
{
void fun1();
int fun2();
}
class MyClass: IMyInterface
{
void fun1()
{ }
int IMyInterface.fun2()
{ }
}
interface IMyInterface
{
void fun1();
int fun2();
}
class MyClass: IMyInterface
{
void fun1()
{ }
int IMyInterface.fun2()
{ }
}
- A function cannot be declared inside an interface.
- A subroutine cannot be declared inside an interface.
- A Method Table will not be created for class MyClass.
- MyClass is an abstract class.
2. Which of the following can be declared in an interface?
Properties
Methods
Enumerations
Events
Structures
Properties
Methods
Enumerations
Events
Structures
- 1, 3
- 1, 2, 4
- 3, 5
- 4, 5
3. A class implements two interfaces each containing three methods. The class contains no instance data. Which of the following correctly indicate the size of the object created from this class?
- 12 bytes
- 24 bytes
- 0 byte
- 8 bytes
4. Which of the following statements is correct about an interface used in C#.NET?
- One class can implement only one interface.
- In a program if one class implements an interface then no other class in the same program can implement this interface.
- From two base interfaces a new interface cannot be inherited.
- Properties can be declared inside an interface.
5. Which of the following statements is correct about Interfaces used in C#.NET?
- All interfaces are derived from an Object class.
- Interfaces can be inherited.
- All interfaces are derived from an Object interface.
- Interfaces can contain only method declaration.
6. Which of the following statements is correct about an interface used in C#.NET?
- If a class implements an interface partially, then it becomes an abstract class.
- A class cannot implement an interface partially.
- An interface can contain static methods.
- An interface can contain static data.
7. Which of the following statements is correct about an interface?
- One interface can be implemented in another interface.
- An interface can be implemented by multiple classes in the same program.
- A class that implements an interface can explicitly implement members of that interface.
- The functions declared in an interface have a body.
8. Which of the following statements are correct about an interface in C#.NET?
A class can implement multiple interfaces.
Structures cannot inherit a class but can implement an interface.
In C#.NET, : is used to signify that a class member implements a specific interface.
An interface can implement multiple classes.
The static attribute can be used with a method that implements an interface declaration.
A class can implement multiple interfaces.
Structures cannot inherit a class but can implement an interface.
In C#.NET, : is used to signify that a class member implements a specific interface.
An interface can implement multiple classes.
The static attribute can be used with a method that implements an interface declaration.
- 1, 2, 3
- 2, 4
- 3, 5
- None of the above.
9. Which of the following statements is correct?
- When a class inherits an interface it inherits member definitions as well as its implementations.
- An interface cannot contain the signature of an indexer.
- Interfaces members are automatically public.
- To implement an interface member, the corresponding member in the class must be public as well as static.
10. Which of the following statements are correct about an interface used in C#.NET?
An interface can contain properties, methods and events.
The keyword must implement forces implementation of an interface.
Interfaces can be overloaded.
Interfaces can be implemented by a class or a struct.
Enhanced implementations of an interface can be developed without breaking existing code.
An interface can contain properties, methods and events.
The keyword must implement forces implementation of an interface.
Interfaces can be overloaded.
Interfaces can be implemented by a class or a struct.
Enhanced implementations of an interface can be developed without breaking existing code.
- 1, 2
- 1, 4, 5
- 3, 4
- 3 only