The super keyword, fairly short chapter, but it really needs a little bit of extra help and some tips. So and some important diagrams. There's something in here, we'll get to it but I was like, kids are never going to get that. I'm not sure I got it the first time through, I forgot. I mean, I did know that but wasn't really pull out in front of us. So, we've been using the super keyword to call constructors, but it can actually do more than that. It doesn't just give us our superclass constructors. We can actually call any method in our superclass by using super. And its method name, so super, it's not just for constructors anymore. That's pretty much all that says. All right, our example we're going to work with is the person class at first. We've got our constructors, but then we've also got a method called getFood. We can have a student class which extends person, we can also have a method called getFood. And we can call our superclasses one by saying super.getFood and that's going to give us back hamburger and then we can add plus Taco on it and I guess students are particular in terms of getting food. They like hamburgers and tacos. Yeah, I think we've could probably could have come up with something a little bit more explicit that was clearly only about students, but that's okay. Now, this is the part that's just hiding in this little piece of text and it's really not really about how that example worked. That example made perfect sense in that when you call Super and a method name, you go to your superclass and you get that. But much more difficult or specific is that if you create an object of the subclass, it always keeps that reference of that subclass or whatever class that created it and whenever it goes looking for a method name, it's going to start with that. Even if you happen to be executing code in the superclass. So, they're going to give us a very tricky code tracing activity with a superclass in a subclass. We're going to create an item in the subclass, but we're going to see at some point we're going to be executing some code in the superclass, but we're going to need to go find a method in the subclass. And so, kind of a shorthand way is to say, look, if you have an object of a particular, always look for a method in that class name first, even if you happen to be currently executing a supered method and you're up in the superclass. And some of your kids, they're going to be like, I don't want to learn this. [LAUGH] It seems silly or whatever, there's probably maybe one question on the multiple choice about it. So if you need to, you can let this one go and you'll see why. So here's the example they have there but they really don't walk through it at all. I'm going to give you some images to walk through it, that said, this is too small to look at, so I'm going to break up. We have the base class and the derived class. And I'm going to break that up in two pictures so you can see it better. What you need to remember is up in the very top, it says base b equals new Derived. Now, it says base b equals new Derived, it doesn't say derived b, turns out that that doesn't matter. It was constructed using the derived constructor. So, any time we're going to need to look for something or when we want to look in the derived class. That's your preview, teacher preview. All right, Base and Derived because it's calling b.methodOne. We're going to start in the Derived class. And I'm going to call method one, what's going to happen there? First thing it says, super.methodOne but ding, I go over there. It prints out A, I'm going to keep track of my output in the bottom left there, fine. Next, we go down to method two, method two, it's defined right below there. That's great. Wait. Why are we going through this crazy example anyway? Base b is new Derived and what we just learned was an object keeps a reference to the class it created which is Derived and always looks for a method during execution starting there. So that means actually even though we're calling method two from inside base because with the class was constructed with the Derived constructor. We're going to actually execute method two from the Derived class. And then of course that just to make life more interesting actually goes off and call super.methodTwo which that, we print B. So now we've got A and B, we're done with that. Next, we're doing that, we'll print D. So now we have A, B, D, we're done with that. We finally just got done with our super.methodOne, [LAUGH] we print C, A, B, D, C, which is the correct answer. And when you click on that correct answer [LAUGH], this whole big paragraph pops up which probably gives you the hint. Yeah, they kind of put this example in there. They had that one sentence that said, yes, this is how it behaves but you're not really going to get it from that unless you've gone through one of these. So again, your students are not going to get this the first time, you're going to forget it at various times, it's okay. Now you've got some screenshots you can go and walk us through but again also this is going to be one small point and it's really not something that we really use a lot in real design. It could be but a lot of people probably have to look this up a lot, practicing software engineers included. Let's jump into our programming challenge, which is about customer information. Three basic things, we have a customer class that keep tracks of names and addresses of customers and it's got a toString method. We're going to create a subclass that inherits it from the customer class and adds a new instance variable, etc. Now, we've been doing this create a subclass thing. We're going to start giving people less and less explicit information about what they need to do. So in fact, the online customer, it should extend customer. It did mention that it needs to have an instance variable and string email, doesn't explicitly say you need to create a constructor but you do and it didn't tell you what parameters needed to come in that constructor. So the students are going to have to interpret and go and read that the customer class requires two things, a name and an address. And its online customer also has an email and then, did you call the superclass constructor and then to set your name and address and then you just set your email instance variable directly here. Next it says override the toString method in the online customer class to call the superclass toString and then add on the email address. And what's hard here is that we're actually returning concatenated strings. That's the only thing that's difficult about this. So we returne super.toString plus and then this slash n, that's how you include a line break or an enter or a new line in an actual string. It won't print out slash then, it'll just make email address show up underneath the name and the address. This is not tested and I kind of wish you didn't muck around with it. But this is the way toString works, toString doesn't actually print something out. It constructs a big string and returns it but this will call the superclass toString and then add on some more things to it.