9.2 also pretty nice and short, all good stuff inheritance and constructors going to do some extra walking through things for you. So you know what to expect and a little bit of a teacher's tip in the square is a rectangle inheritance. So subclasses inherit all the private instance variables in the super class that they extend but they can't access them because they're private in that super class, right? And one of the things that CS also makes a little bit confusing here is we're doing our activities. They're putting both the subclass in the superclass like in one piece of interactive thing, in reality if you were doing that and replicate those have to be into separate files. And that makes it a little clear that of course, the subclass can't directly access the private instance various because they're not in say person.java, they're in student.Java. So this is a problem, constructors we know the goal is they have to initialize all the instance variables. But if your subclass how are you supposed to initialize instance variables that you can't access directly? Short answer you have to call the constructor of your superclass. And we're going to have a cool new vocabulary word, then we can use for that. So they're basically saying how do you initialize those private instance variables? So let's say we're having an employee class, which extends a person. The one thing we're going to want to do not employ class is be sure to call our super classes constructor. And the kind of funky way that you just have to tell students just accept it the way it is, is we don't actually use the constructor name, we just say super, kind of nice because you could be like super. Now, that super will be calling the default constructor in the person class. And down below you'll see you can have super, the name that would call in constructor in the person class that takes a string. So here's the example they have students with it's a person class that's got a private string name. And we've got an employee class, which extends person. And it actually has two separate instance where we're going to ignore the static one. You don't need to be talking about it to understand what we're doing here. But if you want to go back and use this as a way to revisit that, that basically keeps making sure that you get the next ideas always the one after the other one. But one that employee class has is an instance variable that's different than person that's more specific is an ID. The question you're asking is which class employee or person constructor sets the in the name instance variable? Because there is a name, person has a name who's setting it? We said that if you make a new employee, we did not taken the name, but whose code is actually doing that, okay? And we can tell that by here because we can see the in our employee constructor we pass in the name, but I don't say name equal the name, I can't because name is not a variable that's available to me, it's outside of my scope. It's only available in the person class. So instead what I do is I call the constructor of the person class that takes a string and sets the name instance variable, all right? So it's actually going to super, the name is going to go to the person class and run this particular method. This is the constructor, the person constructor which takes a single parameter and it sets the name instance variable to be the name of that parameter. They then ask, which class constructor sets the ID? We can see right there we're setting the ID in employee, right? Sorry, I had thought I had a narrow. It's right there, it's right over there Id = nextId. And that's because not all people I'll have IDs, all employees have IDs. So we're going to be setting that instance variable in this employee constructor. All right, this next paragraph, I'd like you to tell students but honestly, it's kind of okay if they forget. Because you want to tell them to always call whenever you have a subclass with a constructor. They should pretty much always be calling the superclass A superclass constructor, which one, we're not exactly sure, it depends. But what this is telling you is that by the way if you forget Java is going to actually do it for you. But see then it's kind of a mystery as to how things are happen. That's why I like to have kids call it directly. So they realize what's exactly happening, but it will in fact it without you and the reality is even though we've never really talked about this every class we create student, parent, dog, cat, pet, whatever. They actually all are subclasses of the object class that is defined in Java by default. You don't need to memorize that, it's not going to give you a multiple choice question, but there you are. Okay, then there's an example to give kids a chance to try it out. They say we're giving you two definitions MPoint and NamedPoint and there's a big chunk of code and I'll show it to you in a second. But the key thing is that NamedPoint is a subclass of MPoint and MPoint has two instance variables and x and a y-coordinate essentially, and the NamedPoint has an additional instance variable called myName. So they're saying, which of the constructors that I'm going to show you next would be valid in the named point class. So the key thing I want you to notice is you can't directly access the my x and my y instance variables in a NamedPoint constructor. So here are your three options, these are the two that are fine. The first one is the one I'm like don't even show kids this because it is calling the superclass constructor of MPoint implicitly there, even though we forgot to do it ourselves and it's going to call the default one. The third one is okay, because it explicitly calls the superclass constructor from MPoint passing in the x and y the d1, d2. The second one is not legal because it's trying to directly access my x and my y. All right, onto the programming challenge. This is a good one, I mean it's kind of boring but it's really key. So we're going to be doing the square is a rectangle. So one of the things I like to ask, Are all squares also rectangles? Are all squares rectangles? Yes, squares are a subclass of rectangle that happens to be the both of the side lengths are the same, okay? Are all rectangles also squares? No, some rectangles or squares but not all of them. Some of them have wits that are twice as long as they are high and why not? So that's how we can define our is a relationship a square is a rectangle but a rectangle, not all rectangles are squares. All right, so what are we kids going to do very similar, actually we're going to be doing this a lot. So we get a lot of repetition here, make the square class below inherit from rectangle. So you got to use extend add a square no argument constructor that calls rectangles constructor using super. Add a square constructor with a one argument that calls the rectangles constructor with two arguments using super. So let's see what that is. So we extend rectangle, we add this public Square and all we do is say super. And that's actually going to go call this method in rectangle. Sorry, I got the cursor in there. But so it's going to call that it's going to set the both sides to 1. And then the last one square one would takes a single parameter, but then it's going to call the super constructor and rectangle that takes two parameters, which is this one, we send in the same value for the length and the width. Then it says going on comment this and test it to make sure it all works, so I just showed you that. And then it says add an area method to rectangle, not square. It computes the area of rectangle and then all those test it to make sure it works with squares too. And so that it's area length times width, not a big deal, but that's what it's going to look like. And then it says add another subclass called LongRectangle, which inherits from rectangle that has the condition that the length is always twice the width, right? The constructors and test it. So will Rectangle is going to look like is this, it extends rectangle, we've got a poorly indented constructor, no argument constructor. Now, again, we said LongRectangle, cool, the length is always twice the width. And so you'd have to know the order those parameters for length and width there, but that's the way it is, it's going to be width for some in length. And then take one that takes a particular value and then set that up for the side to be one side and then two times that, that's it.