So the last topic we'll talk about here in object orientation is the notion of inheritance. And this is a form of code reuse, and it's one of the more advanced aspects of object oriented programming. So just kind of understand what it is at a high level and then you know where to come back to when you need to learn a bit more about inheritance. So the idea is instead of making a new class from scratch, we actually make a new class by starting with an existing class. We're extending it, or another word for this is subclassing. And it's sort of a situation when you're like I've got this code and I've got this data, and I just need to add a few things to it, and then I'll have a whole new thing. And as you design objects and what we call object hierarchies, you often do this, and it's a form of sort of real clever code reuse. But again, don't necessarily think that you're supposed to know when to use this or why to use this. Right now, it's just terminology, okay? Just terminology. We call these parent-child relationships. The original class is called the parent and the new class is called the child class. Ss subclasses are another word for this. You have a class and then you subclass it. I think extending, inheriting, and parent-child are probably better ways of expressing it than subclassing. So here's a bit of code. Let's take a look at this. This code is unchanged. It's the PartyAnimal code that we've been saying all along. It's the one that we construct and put a name in and now what we're going to do is extend it and so you'll notice that this code down here is the part that's doing the extending. So we're making a new class, FootballFan, and by putting in parentheses before the colon PartyAnimal, that says FootballFan inherits everything that is PartyAnimal, meaning the x, the name, the init, the party. All those methods and data are sitting there, and now we're going to add a new variable. So FootballGan has, in addition to all those other variables, it has points and it has a touchdown method. And self.points is added. We add seven to the points and then we call the party and then it does that. This is calling this method because FootballFan includes x, name, and party, and init, and everything, and all this constructor. So this FootballFan is really an amalgamation of all these things together. PartyAnimal is just this stuff, right? And so we still have two classes. We don't just have one. We didn't erase the PartyAnimal class. And so we take a look at the code that we can run here. We can say, oh, okay, let's make a PartyAnimal Sally. And so that constructs an object like this and then stores that in s and with an x starting on zero. And then we call the party method and that changes it to 1, okay? And so this bit of code, it's as if this part doesn't matter at all because it is a PartyAnimal, it's not a FootballFan. But now if we take a look at this code down here, take this code down here, we're going to construct a FootballFan and pass in Jim. But FootballFan has no underscore underscore init. So that actually uses the underscore init from PartyAnimal because we extended PartyAnimal to make FootballFan. So we inherited all of the good that was in there. So there it's going to make a name, a variable x, which is going to start at zero, a variable name that's going to have Jim in it, and a variable points that's going to have a zero in it. So this j variable has more things in it than the s variable has. And so we can call the j.party and if we call j.party, that goes here and adds one to x. So that adds one to x. And then we call j.touchdown. Well, that comes down in here and adds seven to the points, right? and then calls party within us. So self.party is the current object, i.e,, self and j are the same thing, right? self.party, and then it goes up here and passes self in and it adds one to the x, in this case of this j variable. So this becomes 2 and that's where it prints out, it prints out 7 and 2, and away you go. And so it's a way for you to kind of take all this stuff and stuff it into a class by making a new class and just add the extending bits, the bits that are in addition to the other stuff. So like I said, inheritance is a powerful and wonderful concept. It's an excellent form of reuse. But basically the whole purpose of this lecture was so that I could in the future just use these words and you would understand them as compared to I just want to say method, and I've been saying method all along and it's high time that I defined it. So let's just review one last time. Class is a template. It is not actually a thing, it is a shape of a thing, and we define it and say, when we make one of these things, it's going to have these variables in it, it's going to have these methods in it. And attributes, variables within a class. A method is a function that's inside of a class. Object is once we construct a class, we get back an object. And so object here is the snowman cookies. Class is the snowman cookie cutter. And a constructor is a bit of code that sets up our object, our instance, when it first is created. And inheritance is this ability to create a new class, but take all, import in effect all the capabilities of an existing class. So object oriented is awesome. For the rest of this class we're not going to write any object code, we're not going to use class at all, but we are going to use objects and literally you've been using objects from the beginning of this course. As soon as you said x equals hi, that's an object. And as soon as you said x.upper, you were calling a method, right? You've been calling a method all along. When you're doing something like fh equals open, this thing you're getting back, that's an object. And then you do fh.read or whatever, you're calling a method in the dot operators. So you've been using objects all along. I now am just finally explaining to you when I say call the read method or call the upper method, or what's this little dot and why is that there? So again, it's time for us to understand that. But it will take you a long time before you encounter a problem that's large enough where as part of your solution, you're going to make a new object. But when you do, it's really a powerful thing. I mean, it's a really bad idea for me as a teacher to say oh, write a bunch of objects. It's premature for that. Later is when you will actually learn how to use objects and you'd be like, oh, thank heaven that these objects are here. Okay? So that's all for now. Thanks for listening. See you on the net. [MUSIC]