From the course: Learning C#

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

Inheritance

Inheritance - C# Tutorial

From the course: Learning C#

Inheritance

- [Instructor] As I said at the beginning of the course, C# is an object-oriented language which means that we can build class hierarchies using inheritance. In this video, we're going to use inheritance to expand the Book example that we've been using to represent other types of publications. So here, in the Inheritance folder, inside Classes in the Start folder, let's open up the Book class and we'll start here. So let's imagine that we want to create another type of publication called a Magazine. So one of the ways that we could do that is by creating a new Magazine class which I have here, and as you see in the editor, we could, within that class, define properties such as the publisher, the pagecount, and the price. And if we look over at the Book class, we can see that we have some similar fields. We've got the pagecount and the price. So we've created a problem, here. We've duplicated these fields and if we ever decide…

Contents