Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0132 Inheritance

Classes (but not structs) support the concept of inheritance. A class that derives from the base class automatically has all the public, protected, and internal members of the base class except its constructors and destructors. In C# one class can only inherit from a single class. The following code defines a Person class. Person class has all common fields for all person types. class Person{ public string name; } When declaring the Employee class we can build the employee type based on person type. class Employee:Person{ public string companyName; } Employee inherits the name field from Person.