Back to course

Inheritance

C# Zero to Hero: Comprehensive Programming Masterclass

Inheritance in C#

Inheritance allows a class (Child) to inherit fields and methods from another class (Parent).

Syntax

Use the colon : to inherit. csharp class Vehicle // Parent { public string brand = "Ford"; }

class Car : Vehicle // Child { public string model = "Mustang"; }

Benefits

  • Reusability: Write code once in the parent class.
  • Organization: Create hierarchies of related classes.