Introduction to Inheritance in C#
Introduction to Inheritance in C#: Introduction to Inheritance in C#: an overview, Generalization vs Specialization, Inheritance in C#, Inheritance and…
Updated
- Introduction to Inheritance in C#: an overview (Apprentice): Inheritance lets one class build on another. An archer is a character, so Archer inherits everything Character has, and adds what only archers have.
- Generalization vs Specialization (Apprentice): Generalization moves what similar classes share into a base class; specialization keeps what makes each one different in its derived class.
- Inheritance in C# (Apprentice): A derived class names its base class after a colon. It inherits every member of the base class, but its code can use only the public and protected ones, never the private ones; and every class inherits from object in the end.
- Inheritance and Constructors (Journeyman): When a base class has a constructor with parameters, every derived class must call it with base(...). The base class's constructor always runs first.
- Overriding Methods (Journeyman): A base class marks a method virtual so derived classes may change it; a derived class replaces it with override, and can still run the base version with base.MethodName().