C# ClassesLesson 30Free preview
C# Inheritance
This lesson is part of C# · All levels
Summary
Inheritance makes a derivative class take the field and method from the parent class by writing a colon after the class name. The base keyword is used to access the parent member, including the constructor. Legacy supports logical reuse of code and hierarchy, and can be limited by sealed.
Key points
- The derivative class is written in the format class B: A so that A becomes a base class.
- A derivative constructor can call a parent constructor using the syntax base(...).
- Private members owned by the parent are not accessible to the derivative, while public and protected members are.
- C# implements single inheritance so that one class can only inherit another class.
- A sealed key prevents a class from being inherited by another class.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.