课程: Learning C#

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Inheritance

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…

内容