Now that we’ve discussed most of the basics we need for a C## program, let’s talk about two concepts that are central to how C## (and indeed, all object-oriented programming languages) work: inheritance and polymorphism.

A closeup of a set of $100 bills being counted.Wrong kind of inheritance! But this one is pretty nice… Photo by Pepi Stojanovski / Unsplash

The Sample Project


Contribute to exceptionnotfound/CSharpInSimpleTerms development by creating an account on GitHub.exceptionnotfound


Projects for this post: 9Inheritance and 9Polymorphism


Inheritance allows a class to reuse the properties, methods, and behavior of another class, and to extend or modify that behavior.

The class which implements the original properties or methods and will be inherited from is called the base class; the class which inherits from the base class is called the derived class. A derived class inherits from a base class.

“Is A” and “Is A Kind Of”

When talking about inheritance, we normally think of the derived classes having an “is a” or “is a kind of” relationship with the base class.

For example, a bee is an insect, a Toyota Corolla is a car, and a dresser is a kind of furniture. In these examples, Insect, Car, and Furniture are the base classes, while Bee, Toyota Corolla, and Dresser are the derived classes.

public class Insect { /*...*/ }
public class Bee : Insect { /*...*/ }

public class Car { /*...*/ }
public class ToyotaCorolla : Car { /*...*/ }

public class Furniture { /*...*/ }
public class Dresser : Furniture { /*...*/ }

In C#, we specify that an object inherits from another object using the : operator, as shown above.

#c# in simple terms #c++

C# in Simple Terms - Inheritance and Polymorphism
1.45 GEEK