OK.
Welcome to another lecture, and we are going to go over a new topic in this lecture, and that topic
is going to be inheritance.
So sometimes we want to design our programs around the idea of a relationship between different abstract
data types, which I referred to as 80s.
These are user defined data types just like our car class and we've been using.
So speaking of the car class, if we use that as an example, we might also want to create some new
classes for different subtypes of cars.
So think about something like trucks, sedans, SUVs, right?
Those are all types of cars.
The relationship between a car and each of these subtypes can be defined as an is a relationship.
So a truck is a car, a sedan is a car and an SUV is a car.
And this is very important because this type of relationship will drive the way we arrange and use our
classes in our program.
And this is a relationship is what tells us that we will need to use inheritance.
All right.
So inheritance is going to be a way of kind of organizing our programs and having certain characteristics
of a car be able to be used across these subtypes of cars.
So let's take a closer look.
So here we see our car class, right?
So just think of this blog right here as what we've created so far with the car class.
Then you see arrows going down here to truck sedan and SUV.
These are also classes.
So truck is a class sedan is a class, an SUV is a class.
The car class is what we will refer to as a base class.
It's kind of the overarching king of all of these.
If we go down here, these are referred to as the derived classes.
So truck derived from car sedan drives from car SUV, rational car.
When we say they're driving the same car, we really mean that they are inheriting some traits of a
car, right?
These three things here share some common traits, right?
Sure.
Trucks, sedan and SUV, they all require some type of fuel, whether that be like electric or diesel
or, you know, just petrol or whatever, you know, normal gas.
They also have wheels, you know, they probably have windows.
They say they're going to share some things right, and those things are traits of a car.
But these are more specific types.
The point is is that they might kind of have, you know, the stuff that they share could be captured
in a base class here, whereas each separate drive class might have some additional specifics, right?
Like a truck might have, like a truck bed, a sedan is small, probably gets good gas mileage and SUV
sports utility vehicle.
It can fit more people into things in it, but it's not a truck.
So, yeah, you can see that the relationship between the three is that they're all cars, and that's
the main point.
So we're going to use something called unified modeling language, or UML for short as a way of visually
showing our relationships between these classes.
And it's not only going to be the relationships, but it's also going to lay out our classes as far
as the information that's stored inside those classes.
So your e-mail can help you with designing your code structure.
Sometimes it's nice to lay everything out visually first before you start writing code or kind of jumping
back and forth in between writing some code.
Adding to a visualization or a model.
And then going back to your code.
So let's take a look at this, so here we have our car class.
Our basic car class that we've already been working with, kind of.
Here are the data members.
So this is a UML style diagram here.
It only has one class.
But here's the class name.
This is right here in between these lines is reserved for the data members.
The dating rumours here you see fuel paint, color and mileage, so these are variables.
Another thing is these minus signs here with the minus signs mean is that these are private data members.
So if we are going to create our class, these variables will go in the private section of our class
definition and our header file moving down to here.
These are our member functions.
So here is the data member area.
These are the member functions.
This is a member function area below this line here.
And the plus sign, like you might have guessed, is public instead of private.
So minus this minus means private and plus means public.
So each of these minus signs go with each of these variables, and they mean that each one of them is
private.
The plus signs here mean that these are public member functions.
So what I want you to do kind of is an easy challenge is to implement the car class, as shown in the
email in the previous slide.
And don't worry, I will jump back up to that and you can either write down or screenshot it or just
take a look at it.
You can pass that video on it.
Whatever you like.
So will then make you a male model with the other classes using inheritance and implement that as well.
But what I want you to do right now is just take a look at this right here and I want you to then implement
this in code.
So just make a class.
You should make a header file and you should make a copy file.
And you don't need to worry about like a main file for a client code.
Yet we will be doing that a little bit later, but what you should do is definitely make a header file
that has a public and private section and defines these variables and member functions, as well as
a CPP implementation file that has skeletons for these right here and also should have a constructor.
So make sure that you make a constructor as well.
All right.
So you can go ahead and pass the video and do that, and then I will head over to the editor and we'll
get started.
OK, so I am going to exit out of here, and I already have a new project here and sea lion, but what
I'm going to do is right click here and I'm actually going to say new C++ class instead of separately
doing header and source.
I can just click class.
And it's going to make CP and header file for me.
So what I'm going to call this is car.
All right, so I'm going to go ahead and click, OK.
Of course, though, it would something I love about Sea Lion, you know, it already defined by macro
guys here and everything.
And here we have our head and RCP.
So what do we need to implement?
Let's go back to our dining diagram, so we feel painkiller and mileage as private data members and
these as public, these methods.
So I'm going to go ahead and say public and I will say private.
So my private is going to be a.
We have fuel painkiller mileage, so fuel is most likely going to be in gallons, which I'll put as
an integer, so I'll say and feel.
The painkiller will most likely be a string.
So I'm actually going to say a sturdy string
painkiller, and I should probably put something in here like include ice cream or string.
So we can have access to that.
So then what I want to do is let's see mileage, so I'm also going to have, I think, going to have
mileage as a float.
So I will say float mileage.
Cool, and I like to kind of like name my dad remembers with Underscores before then just as a naming
convention, and kind of this can actually be like turned into camel case like, say, pain killer like
that.
So let's look at the methods we have show fuels that feel get odometer set paint.
So let's go ahead and start doing those as public methods.
So I'm going to have show fuel will probably be a void.
Let's see.
Or no show fuel will probably be an integer because it's going to return.
So let's go ahead and return.
We'll put an end because it a return the fuel.
It will basically be like get fuel, but get fuel sounds like you're actually getting gas and putting
gas when we really just want to return the what the fuel is.
So that's why I'm playing a show field.
So if they show fuel returns and aren't.
Set fuel, so set fuel will take an integer and it will be void.
So say said fuel and this will take an integer fuel.
Then we have get odometer.
So let's go ahead and do that, so get odometer should return the mileage, so that will be afloat,
right?
So I'll say get old down there, then we have set paint and get pain.
Now let's actually get paint.
So let's go ahead and do that.
So we'll say set paint will be void, set paint and this will be a string.
Color and then we'll have to get paint, will return a string and say, get paint like that.
OK, OK, cool.
So I think that handles everything here for the car class.
So let's go ahead, and since I'm a sea lion, I can actually just choose to.
Make create definitions for these so I can go here and I can't say generate definition for show fuel
that'll generate that here.
I was saying, I just can't do that for each one of these.
So generate definition for set fuel.
Any definition for ODOMETER?
So this is a really nice thing about sea and that I like, and so you can just click and it'll generate
the definition for you.
All right.
And you can also generate it in place, you see, so you can actually put implementations here in the
header as well.
But we're going to separate them out into the CBP.
All right, cool.
So another thing that we needed was our constructive, though, right?
So I'm actually going to say car as a constructor and then we're going to set these two default values.
So let's go ahead and head over here.
So let's osteria definition for this to.
Cool.
So I actually want this to be of top, so I'm going to.
See, I keep it small for now, because I'm going to just grow up here and do that, but then I'll see
you in in just a second.
All right.
So let's go ahead and set our data members, so we want to and let's see where painkiller fuel and mileage,
and he said fuel to zero.
So let's just say we start out with zero.
I know before I think we started out with fuel or something else, but let's just pretend that when
you have the basic car, it just comes with zero fuel.
So maybe like there's some initial gas like feeling that we have to do right away.
So paint color.
We'll just say, uh, well, when it started out as just say white.
It just starts this white.
And then we have our mileage.
So let's just say mileage starts at zero point zero, right?
So what?
The car was no miles.
So there's I command structure.
All right, so show feel this will just return the fuel.
So let's just add fuel there, their set fuel.
So this will just be fuel equals fuel underscore fuel equals fuel.
So get odometer will return mileage.
And then set paint will just say paint color equals color.
And so get paint will just return paint color as well.
OK, so another thing just to point out, you know, if you haven't noticed this already is that a big
part of the object oriented design is having accessories and mutations or setters and getters.
You can refer to them either or.
So.
The senators are basically mutations and the Kennedys are accessories, so this is a getter.
So what it does is it just returns on to the private data members to you.
This is an important concept of encapsulation.
So I might have said this already, but I just kind of want to reiterate if I haven't.
So encapsulation is an important concept that has to do with us kind of protecting our data members
and only exposing things to the user of our library or just our code.
Whoever is instantiating our classes, we want to kind of force a certain behavior to for interaction
with our data.
Right.
So we expose kind of this interface for people to access our data, and that's through setters and getters.
So this right here is a ganar function.
I wouldn't call it get fuel, but I think she'll feel sounds more appropriate.
It's just returning a value and you notice these setters.
What they do is they instead of returning the value, they set a value so the user passes in a value
and the data member of our class gets set to that value.
You know that like this is just a series of setters and getters.
It's basically like you get the full set, the fuel, get the odometer.
We haven't done.
Let's see.
The get odometer.
We don't set the odometer, so that doesn't have it.
This is just a get road down downer, but we have, you know, get fuel, set fuel, get the odometer.
We have set paint and get paint.
So these are all like series of setters and getters, which is an important concept for object oriented
programming and definitely a good technique to use when you're programming.
So I think that kind of does it for setting up our car class, you know, keeping it pretty basic.
This already came with a client while I said you didn't have to make it, but when I created my project,
it just put this made seep in here for me.
So if you want to add that you can, but you don't have to right now.
So let's head back over here to the slides.
So we already had and went ahead and implemented that, so now we're going to talk about inheritance
and we're going to use you and Mel to show what inheritance is doing.
So before I show the inheritance relationship between these classes in, you know, how you're supposed
to show it.
I'm going to go over some of these other classes here.
So here we have our base class, right?
We just implemented this in code.
So let's think about what the other classes would look like the derived classes of car.
So a truck and these you can put kind of whatever you like in here.
But I'm just I just put this stuff here because I thought it was simple and made sense, doing kind
of segregated stuff and having some data members that have to do with the specific type of car.
So trying to keep it simple, just so we can focus more on the concept of inheritance and having subclasses
drive classes rather than getting into some details of some implementation of a class.
So let's look at trucks, so truck has two private data members.
Bed length.
So how long is the bed of the truck in the back to store stuff and then a is full cab?
So this sounds like a Boolean, right?
Like it is full cab is either a yes or no thing.
So we have this private Boolean as well that tells you whether it's full cab.
Our methods here set bed length, get bed length set is full cab and get it full cab.
Our sedan here, we have private members as the number of doors, so as the two door or four door or
something like that we have is compact to just know if it's like a small compact car and the bullying
as well.
And then we've got setting on doors.
Getting some doors set is compact and get is compact.
So pretty simple, you know?
Methods and stuff here, you know, we're not going to crazy SUV, has no seats or is all wheel drive,
so you notice that we have this pattern of like integers and billions for our data members and then
we have setters and getters for those.
So we have seats, get seats and set is all wheel drive and get this all wheel drive.
Cool.
So if you're looking at this and you smell, it would be represented with something like this.
So.
There will be an arrow.
It has kind of an empty arrowhead coming from these free classes.
And the empty arrowhead means inheritance.
So what it means is that these three classes here are kind of extending the car class.
So what that means is that they are inheriting if you're thinking about it going down this way, when
we had arrows this way, it's like truck is inheriting from car sedans, inheriting from car SUVs inherited
from car.
When you look at it from this way you, you're basically seen it as an extension.
So you're like truck extends.
This class sedan extends this class SUV extends this class, and that just means that each one of these
classes will be able to have access to the public data member.
Sorry, the public information of the car class.
So these are private data members, so we will not be able to refer directly to these.
But what we will be able to use is when we make a sedan object, for example, we will be able to call
these public methods on a sedan object.
It doesn't always have to be like the inherited class being extending it in a public way.
We actually can do it.
I should probably put a tee there for the paint.
We actually can set that up differently as well, but I will get into that later.
But the point is is that we will be able to today when we're implementing these derived classes, we
will be able to make an object of each one of them.
And if we want to, we could do track dot, get paint, truck dot set feel.
Of course, in addition to trucks, get bed length and stuff like that.
So it's inherent in the functionality.
Each one of these is inherent in the functionality of this car class, as well as some of the data,
potentially.
But these are private and we're not going to be using those when we're doing this public kind of inheritance
in this lesson.
So that is the point that they are all cars in, so you can access these methods that have to do with
a car.
I mean, a sedan is a car, it's going to have paint and it's going to have an odometer, right?
Same with an SUV.
They're all going to share these methods up here.
So SUV will have access to this sedan, will have access to this truck, will have access to this.
But then you notice that each one of them has their own methods and data that is specific to the subtype
of car.
Right.
Truck has bed length.
Sedan doesn't have that length.
It's not going to have a bed, an SUV, not going to have a bed, either.
So that's why, you know, they each have their own stuff in here as well as sharing stuff.
All right, so let's go ahead and implement it.
So we're going to head over to the editor and we're going to try and implement when we described in
this new normal model.
So if you need to, you can always go back and parse it right here.
Take a look at this new email so it can help you implement it.
But you can just follow along, too.
Because I'm going to go over it.
All right, and we're going over some of the syntax that's needed to use inheritance as well.
OK, so we're going to go ahead and make some more classes, why don't we go ahead and do that first?
So we want to make our draft classes.
What I'm going to do is just go over here.
I'm going to right click on my inheritance folder and I'm going to say a new C++ class.
So what I'm going to do is call this one truck.
All right.
So.
Let's go ahead and get stuff started and we'll make a
public and private.
But one thing that we want to do up here is I'm going to include the car h class and then what we're
going to do if we're actually going to put a call in here and then we're going to say public and car,
and now I want to put public car.
You notice that this pops up right here.
It says, go to super type.
So what this is is this is the syntax for declaring that the truck class is going to inherit.
Publicly, as a access specify, this is like an access pacifier for the class, the super class, which
is car.
So this syntax here is saying that the class truck, I want it to inherit from the car class.
And when it says go to super type.
Another thing that you can say is that car is a super class four truck sedan, an SUV.
So it's a super class, it's a base class.
You just think of it as like the ultimate class.
But people quite often refer to it as the base class or super class.
And this is the syntax to inherit from that super class or base class.
You put a colon, you put the access, specify a type which we're just going to be doing in public right
now.
And then you put the name of the class.
OK, so let's go ahead and start implementing some data and like data members and methods.
So if I go back here, I think I can.
Yeah, we have the Sudan truck bed length and is full cab.
Cool.
So we'll stay in bed length and below is the full cab.
Now, let's check this out, so we have the.
Let's see.
Set bed length.
Get bed length.
Public methods, so we will say and set bed length and this will just be in length and then we will
avoid or actually leave my bed.
This is vice versa, Boyd and and get fabulous in this or just return the bed length.
What was the other one?
So we have yes, it is full of gas vocab.
So we'll have this.
Let's see, Boyd said.
It is for CAB.
So this will be.
And I'll just call this cab or something like that.
So then we'll have a pool as returned by get is for cab.
So we could also change these, we could just say, you know, you could just say like.
Uh, you know, is full cab, I can kind of show you that in a bit, but there is a way that we can
just have it be kind of all in one.
So I might go back over this and kind of show you how you can have setters and getters combined in one.
But for right now, we're going to separate them.
OK, so these are all of our methods here.
So actually, we probably want to put a constructor, right?
So we'll do a constructor.
So go ahead and just say generate definition for that.
And then we will.
Generate definition for this.
Cool.
Or.
You know, you can kind of do it two ways you can just like, hover over it.
And then click on it, or you can actually click on it and then do the light bulb.
All right, so we should say our data members here, right?
So we have, let's just say, bed length starts out.
I don't know what the default bed length would be.
We could just say like six, four six feet or something like that and then is full have let's just say
that's kind of an upgrade should be like initially set to false.
All right, so this will just be setting the bad links, so the safe bed length equals its length and
then get bed length is just going to return badly to us.
City's full cab, so that's just is full cab equals cab.
And then get is full cab and just say the turn is full cap, so pretty simple here we just have our
setters and getters.
And that should be everything for our truck class.
So, yeah.
I think we're good to go there.
So I'm actually going to I'm just going to say this all right now, but I'm going to get out of.
These so we can kind of make some more.
Some more room when we do the other ones, so let's go ahead and make another class, so I'm going to
say new C++ class.
This one is going to be sedan
and I would kind of encourage you at this point actually to maybe pause the video and see if you can
actually implement the sedan class and the SUV class.
This would be great practice and would help you learn better than just watching me go through the motions
of doing this.
You've already seen how we did it for truck.
It's going to be very similar.
You can reference the UML that we had to be able to create those classes.
So if you can go ahead and try to pause the video and finish the other two before I walk through it.
All right.
Well, I'll go ahead and go right, though.
So I'm going to go ahead and include the card each year, and then what we're going to do is our inheritance
rights.
I'm going day public car and you see that superclass thing pop up.
So if I click this, it'll take us to car, so I click there.
It takes us to car that age and then you click here.
It says, Go to subclass.
I click here and it gives us sedan or truck.
All right.
So nice way to navigate around here.
So let's go back to sedan age.
So I'm going to go over here and I'm going to say public and then I'm going to say private.
And we should have, let's see, no doors and is compact.
Services and no doors and pull is compact.
So then we should have some methods, right, so we will have.
And you get no doors, no return yet, and then we'll have set no doors.
Well, you hear and doors and then we'll have a ball which will be get is compact and we will have one
which is set.
Yes, contact will.
And we'll just say,
all right, so it's going to hover over these and generate these functions.
And I also need to do a constructor because I haven't done the constructor yet.
So I'll go back here and I'll just say to them,
and let's generate that, but I also like to have this on top.
All right, cool.
So let's go ahead and saying it is compact equals false, and I'll just say no more doors equals two
door, just start out with, but normally it should be.
You can kind of upgrade to four door.
Maybe.
OK, getting them indoors.
So it's returning them doors, setting some doors.
This is just going to be on back and doors, people's doors assuming a little because I've seen.
So return is compact and set as contact will just be campaigning people's confidence.
All right, cool, so we should be good to go now and Thurston TPP, so out of these and then let's
go ahead and do our last one, which will be the sedan or the SUV.
Sorry.
So I will say SUV and press, OK, so.
Oh, cool car.
Let's go ahead and set our inheritance.
All right, so public and private.
And what do we have here, no seats and is all wheel drive.
So and no seats and pool is all wheel drive.
All right.
So first off, this time I'll make my constructor actually.
And then let's go ahead and do an hour
and get no seats or Senate seats,
and then we'll have our floor.
It is all wheel drive
and
all wheel drive rule, and I'll just say,
All right, cool.
So go ahead and generate definitions for these.
OK, cool, so we can go ahead and save our constructor now, so I'll say it's all wheel drive is false
to start out with, but that also seems like kind of an upgrade it and then we'll say no seats equals,
let's just say defaults to five.
But you can have extra rows and stuff, you know, bigger versions of this SUV.
Uh, so we'll just say and turn them seats, nine seats, seat or seats for this one.
Sorry, I didn't come in there.
So
return is all wheel drive and this will just be
is our drive eagle.
So will drive.
All right, cool.
So that should be.
Good to go.
So now, if we go back to some angst out of here, go back to our car class and click on this right
here, go to subclass you notice we have three subclasses that we can go to.
So those are all set up now.
So now what we want to do is go over to our main client file and kind of test this stuff out.
So let's go in here, I'm going to include Zoom in a little bit.
I'm going to include our classes here, so I'm going to include the three, the three subclasses, the
three derived classes.
This is what I want to do.
So I'm going to include trucker h.
I'm going to include.
Sedan age, and I'm going to include the SUV age.
So what I want to do now is make objects of all three of them, so I can just say truck and truck.
A sedan sedan and SUV SUV.
And so let's just call some methods on them, so I can say truck dart.
Uh.
Let's just say, let's see, we have let's check out what we got here, so you notice we have get paint
all these options right here and we can go down with so these get paint and get odometer.
Remember, those are not part of the truck class.
Neither is fuel and so fuel.
So you see that we're all right.
We already have access to these because we inherited from our car class.
So we can call a lot of these.
So if we just say that fuel and let's just say we put 12 gallons in there and then we say truck that
maybe like set paint and just put some horrendous color in here like purple or something like that.
And then what we can do is.
Also, do something maybe like set bed length, and we'll just say the bed length is like eight feet
or something, and then so now what would be kind of cool to do is maybe make some stuff that could
print out our objects, right?
So this would be good practice.
So what I want you to do is actually pause the video if you can.
And for each class, I want you to create overloaded output operators.
So the output like like so we can print it out and see out.
So you know how to do that now since you've seen the overloaded operator VIDEO So why don't you pause
the video and go ahead?
And for each of the derived classes, you should make an overloaded operator?
So let's go ahead and see what that will look like implementing those upgrades.
First, I'm going to need to kind of do the same thing for these other classes.
So I'm going to say Sudan Dot like, let's get the fuel first, actually.
I said fuel 11 or 10, 10 and then we'll do sedan setting doors.
Uh, let's actually set the paint and
the paint, and we'll just say this is blue, and then we'll set the doors to like four.
It'll be a four door.
Let's do the same with the SUV.
We'll go ahead and set your first or say that this is like 11.
We'll do an SUV that set paint and this will just be
our new black.
And then let's do SUV dot.
This is all a drive to.
And I said the number of seats to six feet that said nine seats to eight, so do big sedan, OK?
So we have some stuff set up with our cars now.
So our car types, so let's go ahead and do this overloaded operators and see how that works out.
So I'm going to go over to, let's see, we'll do my truck.
Trucker H.
So irony, like put one right here.
So let's go ahead and go to the truck that CP or we can implement it.
So if you don't remember, it is actually going you the base here.
You don't remember, it's just going to be a friend function and then you're going to do a video stream
and operator and then you're going to put the studio stream passed by reference outs for the stream.
You call it whatever you want, but then you want a constant object by pass by reference as well for
us to print out.
So let's go ahead and start printing out some stuff, so we want to not only print stuff about the truck,
which is like bed length and it's full cab, but we want to print everything about it, right?
And there's some other stuff in car.
That we want to try not to like fuel painkiller mileage, we want to print those out, right?
So let's head back to our truck stop and start cranking now, some would say outs.
And let's just first print a line and just say, you know, truck info, and then we'll go to a new
line and I'll say, Alex, and let's start out with like, let's just start out with like fuel
and then let's go ahead and do T dot fuel.
Oh, wait, where's fuel, though?
It's not on here, huh?
So you might have ran into this error when you were making the outfit streams and been like, Well,
I want to print out all the stuff about it, but.
Why can't I print it out, I can only print out this stuff that has to do with a truck, but there's
more things that have to do with all cars like fuel and odometer mileage.
This stuff, right?
Mileage.
Painkiller fuel.
Why can't I print that out, why don't I have access to that?
Well, I kind of set this up so you would run to that problem and then kind of, you know, I could
solve it right now and tell you what the solution is.
But really, all you have to do is go back to this card age.
You notice that we're what we're doing is inheriting publicly.
So if I go to check that age, we say public car.
So this is the access specification.
We don't necessarily even need to change that, though.
The problem is, is that this is private right here.
But what we could do instead is instead of private, we can just change this to a word called protected.
So protected is like private.
But it doesn't.
It gives.
It doesn't really give access to these items when you instantiating the class that has the protected,
but it will give access to derived classes, so derived classes of car will now have access to these
protected members.
They're not.
They don't have access to private that they have access to protected members.
But you cannot and, you know, protected you still can't like instantiating have access to it.
So go ahead and check this all out.
But now you notice when we go back here to check CPP, I go T dot, and now it gives me a much bigger
list.
Look, I have all of them so I can choose fuel
and put it in line.
And then now we can do the rest, right?
So we'll say color and all.
You know, there's somebody like paint color,
and then I'll say, we have the odometer.
Mileage
and then we have been on at length about that length,
and then we have watched the last one, so is full cab, so has all.
Cam.
All right, cool, so that's pretty much all of our truck info there.
So we got fuel odometer, Melissa, fuel color, odometer and length and has full cab there.
So we're going to pretty much do the same thing for the other classes, so we could just copy paste
a lot of this.
So what I'm going to do is we'll go ahead and get a card each.
We'll do sedan h.
And I'm actually.
Just going to copy this, and I'll put that here.
What we're going to do is change this actually to Sudan.
And I'll call this Earth, and we'll go ahead and generate a definition for this.
This is going to turn out.
And what I'm going to do is I'll just copy this stuff and check that copy and modify it.
So let's head over here and zoom in a bit.
Cool.
So this is actually just going to be as
quick.
So that goes so this bed length stuff.
We're not really going to do that.
This is going to be something else.
So this will be, we'll say, uh, no doors.
So and then this will just be.
I say is home packed and or a that is compact?
Close, so pretty quick fix to get that one going.
So let me go ahead and copy this.
And we will paste this over an SUV now.
So.
And this Naomi sedan will be SUV.
Let's go ahead and.
Generally a definition for this.
I'm going to go here and I'm going to copy this.
We actually want to change this to two Sudan info, right?
And so.
Who are so happy this year.
Pace would be SUV and fell.
And of course, these last two, we want to change.
You don't want no doors.
We want to say like no seats, right?
So no seats.
Seats and then asked is compact is actually going to be asked.
It's all wheel drive, so we'll say it's all wheel drive and then we'll print that out.
OK, cool.
So now we pretty much have everything set up, so now we should be able to print out our objects.
So you also have these accessories as well that will be able to get.
And, you know, we're not using to get it in here, but we can use that in Maine as well.
Cool.
So let's go ahead and print this stuff out, so I'm just going to say, see, see out and we'll just
say truck.
And then we'll say.
So then and I might go added some of those to have line, but
we can print all these out.
So I might go ahead and just add in lines to these.
So.
I only have actually only have it in line after that, so.
Yeah, let's just do.
Copy paste this into a couple of places, because I just want to kind of like an extra line.
All right.
So go ahead and save all of this, and then I'm going to go back to my main and then I'm going to go
ahead and just run this.
And if everything is good to go, we should see our info print out.
Cool.
So we see trucks and an SUV in, so we print this out, truck info says fuel 12 color purple odometer
zero bit length eight has full cab.
That's just print out is zero because it's true or false, like one zero.
So we could set this.
So what if we say that the dot
set is full cab and we'll say true?
So now if I run it.
You notice that we see a one here because it's true.
So like one is true, zero is false.
Sudan Info.
You see it matches up here and then we have our defaults.
Cool.
So, you know, our donors always zero, it might be good to have some function, says Drive.
And it like drives a little bit, makes the miles go up, but you know that could actually happen when
we add some more interfaces and stuff into this.
So I think this was enough to just go over basic inheritance.
I went over a lot of important concepts, and I don't want to stuff too much in here, so it's not too
overwhelming.
And one lesson.
But so what you've seen is how to make a base class, right?
You notice here it says it gives you access to all these subclasses and then we can look at each.
Subclass, for example, as you've been on age and you notice that here, it gives you access to go
to the super type.
And this is how you do the inheritance, you know, a colon and then right for right now we're just
doing a public access to fire and the name of the superclass or the base class, which is car, make
sure to include that as well.
And then you noticed that one of the things that we had to do in the base class for us to have access
to the data members here for our alpha operator are over that it was to change this, to protect it.
All right, cool, so hopefully that was enough for you to get a general idea of inheritance where of
course, going to continue on and kind of of the of this in terms of complexity, and we'll start talking
about some related topics such as polymorphism.
All right.
So with that, I will see you in the next lesson.