‫Welcome back.
‫In this video, we are going to use what we have seen in the last video in theory, but we're going
‫to do a demo here.
‫So we are going to create our own class, which is a blueprint of a data type, so we can create our
‫own data types by creating a class.
‫And that class can have properties, that class can have methods and so forth.
‫So let's go ahead and create a new class.
‫So I'm going to right click onto my C shop level and I'm going to create a new class here and I'm going
‫to call that one human dot CSS.
‫So now let's go ahead.
‫In my human class, I want to create members.
‫And members are, for example, variables, members can be methods and so forth, and they are called
‫members because they are part of that specific class.
‫So let's say I have a member variable and for a human that would be, for example, a string called
‫first name that would be a great member variable.
‫And so this human.
‫Is our data type so I can create.
‫An object off of that.
‫So I'm just going to create a human now I'm going to call the human.
‫Dennis is a new human and that's how I do it.
‫So this is how I create an object of my class.
‫Or also called an instance of human.
‫So this instance is called Dennis, and now this Dennis has a first name.
‫So if I would like to change the first name, there are multiple ways to implement that.
‫You could do that with a constructor and so forth, and we're going to do that.
‫No worries.
‫We're going to do all of that.
‫But I'm going to keep it simple in this video.
‫So you first of all understand that this is actually a blueprint.
‫So Class Human is a blueprint now.
‫And let's say I want to introduce myself.
‫So this human class has multiple capabilities or skills.
‫So, for example, you can drink.
‫All right, how much can you drink or how much do you drink?
‫So each time you drink, you could have a parameter.
‫How much did you drink?
‫So in order to see how hydrated you are, so let's say there is a hydration level from 0 to 100.
‫How hydrated are you?
‫And each time you drink, let's see, let's say half a liter.
‫Then it increases your hydration level by 30% or by 40%.
‫So that's how you could, for example, design a human in programming purposes.
‫So what I'm going to do is I'm just going to create a method which will introduce me.
‫And this is going to be a member method because it's part of my human class, which is a blueprint.
‫So this class is a blueprint for a data type, and this method is going to be a void, public void,
‫introduce myself.
‫And what it will do is it will simply write something onto the console.
‫It's going to write something like, Hi, I'm.
‫And then it's going to write the first name.
‫All right.
‫So now, as you can see, first name doesn't have a value.
‫And if I try to store something into Dennis, so if I try to change the first name, I can't do that.
‫That's because it's protected and it's protected because there is no public before that.
‫So if you don't add a public, this variable is going to be protected and not accessible from outside.
‫So from outside this class, I can still use it within this class, as you could see, because I have
‫used it here and it was no problem.
‫But if I make it public, I can now also use it from my program CSS so I can simply say Dennis first
‫name and I'm going to set that.
‫So I'm going to set that to Dennis.
‫Now I'm going to introduce Dennis.
‫So Dennis is going to introduce himself just like that.
‫So you see, this is how I can access private or actually is a public public variable from outside.
‫And even change it.
‫And this is how I can call methods of the class or in this case, of the object.
‫Dennis So Dennis is of type human, which means it's of this class type.
‫So this is the blueprint and it has a method called introduce myself.
‫And this is the method that I'm going to call here.
‫So if I run the code and in order to see something on the console, I also want to read the key so my
‫console doesn't shut down straight away.
‫And that we are so high and Dennis is written onto the console.
‫So let's say I create a new object which I'm going to call human.
‫Michael is a new human.
‫And now if I introduce Michael, so introduce myself.
‫If I just run the code like that, you will see that it just says high empty space.
‫And that's because we didn't set the name of Michael.
‫So let's say we want to save the name or change the name straight, straight away in here.
‫So I'm just going to say, Michael, here, let's test that.
‫Let's run the code.
‫And in this case, it's actually going to work.
‫So it's going to say, Hi, I'm Dennis and hi, I'm Michael.
‫So what we do here is we say every single human is going to be called Michael as long as you don't change
‫it.
‫So Dennis has actually actually changed it, but Michael has never changed the name.
‫So Michael is still going to be Michael.
‫But if we, let's say, change the name Michael to Michael or something like that.
‫So let's say he wants to introduce himself in a different language and there he's going to be called
‫Michael or for example, Michael would be an option then.
‫It would be overridden.
‫And we see.
‫Hi, I'm Dennis.
‫And hi, I'm Michael.
‫All right.
‫So this is how you can actually make sure that this always the same.
‫So this variable is going to be always the same first name, except you change it.
‫So now if I make it private, so let me stop that.
‫I'm going to make it private string Michael Now I'm going to receive an error here because I cannot
‫change the first name because it's private now.
‫So neither Denis nor Mike, Michael or Michael can now change their name.
‫So those two objects are going to be.
‫The same.
‫So it's going to be.
‫Hi, I'm Michael.
‫I am Michael.
‫So they don't differ in any way.
‫So now you see why it makes sense to make this method here public.
‫And it's actually a public method, and it really doesn't seem to make sense to make this private,
‫because now I cannot change it.
‫Well, actually, there are, as I said, multiple ways to change it.
‫One of them is creating a property.
‫The other one is to create constructors, and we're going to do both of that.
‫So I'm going to start off with constructors in the next video where you will see how to go ahead with
‫that.
‫So now, first of all, a little challenge for you.
‫So create a public variable last name of type string change, introduce myself method.
‫So it tells the whole name.
‫So it doesn't just say the first name, but also the last name.
‫Then create two objects with full information about themselves in our program CSS.
‫So in the main method.
‫All right.
‫I hope you pause the video and try to do that.
‫So let's go ahead and I'm going to make it public starring last name, which is going to be empty for
‫now.
‫The same here.
‫I'm going to change that first name to not being Michael anymore because not everyone is called Michael.
‫Then I'm changing.
‫Introduce myself to also tell the last name.
‫So I'm going to need that here last name.
‫And now let's create two objects with full information about themselves.
‫So I'm going to get rid of.
‫So actually let me just clean up everything here.
‫So first of all, human and I'm going to call her Sissy is a new human and now Sissy has a first name.
‫So first name is going to be Sissy and her last name.
‫Well, actually, I don't know what Sissy last name is.
‫I'm going to call a Wagner.
‫And then we have Sissy who introduces herself, introduce myself, and now we have a different person,
‫human frontal, new human.
‫And that frontal is going to be called actually frontal.
‫It's a very uncommon name, but it's a very old funny name, an Austrian.
‫And that frontal last name is going to be Mila.
‫You can actually write it with you as well.
‫You don't need to use this this special sign here.
‫Okay.
‫And that person should introduce himself as well.
‫So introduce myself is what he's going to say.
‫So let's run the code and we see.
‫Hi, I'm Sissy Wagner.
‫Hi, I'm Franz Von Miller.
‫So there we are.
‫You see how to use human or how to use your own data type.
‫So we're going to look into that a bit more because for now, as I said, this is just a member, just
‫a variable.
‫And I talked about properties earlier on.
‫So for example, length was a property, but properties are written with a capital letter at the start
‫and we're going to look into properties and of course we're also going to look into constructors because
‫why would I have to do it this way if I can simply do the whole thing in one line?
‫So let's say I could enter something like Sissy and Wagner right here, and that human would already
‫be created.
‫Then I wouldn't have to do all of these additional lines, so I could simply do that in the same line.
‫And that's exactly what you can achieve by using constructors, and that's what we're going to do in
‫the next video.
‫So I hope you could manage to do the little challenge that you have here.
‫In the next video.
‫We're going to have a look at constructors first before we go into properties.
‫So see you in the next video.