1. What is inheritance in C#?
Answer:
Explanation:
Inheritance in C# is the process of deriving new classes from existing ones, allowing the new classes to adopt and possibly extend the properties and methods of the base class.
2. What keyword is used to inherit from a base class in C#?
Answer:
Explanation:
In C#, the colon (:) is used in the class declaration to inherit from a base class.
3. Which class in C# is the base class for all other classes?
Answer:
Explanation:
In C#, the 'Object' class is the ultimate base class from which all other classes implicitly inherit.
4. Can a derived class override a non-virtual method of the base class in C#?
Answer:
Explanation:
In C#, a derived class can only override methods in the base class that are marked as virtual, abstract, or override.
5. What is the correct way to call a constructor of the base class in C#?
Answer:
Explanation:
In C#, :base() is used within a derived class constructor to call a specific constructor of the base class.
6. What is the default access modifier for base class inheritance in C#?
Answer:
Explanation:
If no access modifier is specified for inheritance, the default is 'public' in C#.
7. Can structures (structs) in C# inherit from other structures or classes?
Answer:
Explanation:
In C#, structures (structs) cannot inherit from other structures or classes, but they can implement interfaces.
8. What is the purpose of the 'sealed' keyword in relation to inheritance in C#?
Answer:
Explanation:
The 'sealed' keyword in C# is used to prevent a class from being used as a base class, effectively stopping inheritance from that class.
9. What is multiple inheritance in the context of C#?
Answer:
Explanation:
Multiple inheritance, or inheriting from more than one base class, is not supported in C#. However, a class can implement multiple interfaces.
10. Can a derived class in C# access private members of its base class?
Answer:
Explanation:
Private members of a base class are not accessible to derived classes. Derived classes can only access public, protected, and internal members of the base class.