1. Which of the following statements is true about inheritance in C#?
a) C# does not support inheritance.
b) A derived class inherits all members (fields, methods, properties) from its base class.
c) A base class inherits all members from its derived class.
d) Inheritance can only occur between classes in the same namespace.
Correct Answer: b) A derived class inherits all members (fields, methods, properties) from its base class.
2. What is the purpose of the "abstract" keyword in C#?
a) To prevent a class from being inherited.
b) To specify that a method does not have a body and must be implemented in derived classes.
c) To indicate that a method can be overridden in derived classes.
d) To declare a class as a blueprint for creating objects.
Correct Answer: b) To specify that a method does not have a body and must be implemented in derived classes.
3. Which of the following is NOT a valid access modifier in C#?
a) internal
b) protected
c) private
d) friend
Correct Answer: d) friend
4. What is the purpose of the "base" keyword in C#?
a) To specify the base class in a derived class constructor.
b) To access the derived class members from the base class.
c) To indicate the end of a code block.
d) To specify the entry point of a program.
Correct Answer: a) To specify the base class in a derived class constructor.
5. How do you define an extension method in C#?
a) By using the "extension" keyword.
b) By adding a static method to a static class and using the "this" keyword before the first parameter.
c) By using the "extends" keyword.
d) By adding a non-static method to a non-static class.
Correct Answer: b) By adding a static method to a static class and using the "this" keyword before the first parameter.
6. What is the purpose of the "sealed" keyword in C#?
a) To prevent a class from being inherited.
b) To indicate that a method can be overridden in derived classes.
c) To specify that a method does not have a body and must be implemented in derived classes.
d) To declare a class as a blueprint for creating objects.
Correct Answer: a) To prevent a class from being inherited.
7. What does the "yield" keyword do in C#?
a) It yields control to the next iteration of a loop.
b) It specifies the exit point of a method.
c) It is used for exception handling.
d) It returns a value from a method.
Correct Answer: a) It yields control to the next iteration of a loop.
8. What is the purpose of the "readonly" keyword in C#?
a) To declare a constant variable.
b) To prevent a variable from being modified after initialization.
c) To specify that a method does not have a body and must be implemented in derived classes.
d) To indicate the end of a code block.
Correct Answer: b) To prevent a variable from being modified after initialization.
9. What is the default access modifier for members of a class in C# if no access modifier is specified?
a) public
b) private
c) protected
d) internal
Correct Answer: b) private
10. What is the purpose of the "as" operator in C#?
a) To perform type casting.
b) To check if an object is of a certain type.
c) To create an object.
d) To specify the entry point of a program.
Correct Answer: a) To perform type casting.
Feel free to ask for explenations in the comments if you have any questions.