‫Welcome back.
‫In this video, we are going to have a look at the different amounts of constructors that we can create.
‫And they are limitless, almost at least, at least as much as you have space in your memory, but you
‫can create plenty of constructors.
‫So that's the general idea.
‫We have created a constructor here in our last video and that constructor is a parameterized constructor.
‫Parameterized constructor.
‫Now we don't need to create a parameterized constructor.
‫We can even create a non parameter write constructor.
‫So a default constructor.
‫So let's create a default constructor at the top and I'm going to call it public human.
‫And in here I'm just going to write something on the console.
‫So see W constructor called or you could even say object created.
‫So that's pretty much it, nothing else than that.
‫So now if I do that, as you can see, we have a parameterized constructor and now we have a default
‫constructor as well.
‫Default constructor.
‫We can create an object of type human that doesn't have any further information yet.
‫So human and I'm going to call that basic human is going to be a new human.
‫That's it.
‫So now basic human doesn't know how to reduce themselves.
‫Of course we can call that method basic human, introduce myself, but there won't be much information
‫given.
‫So if we call that, we say constructor called object created.
‫Hi, I'm zero years old.
‫My color is so there is no information given because this basic human well as I said, it doesn't have
‫any further information.
‫So as you can see, we have already two different constructors, but we can even create more.
‫So we could even go ahead and copy that one here.
‫So let's copy the constructor that we had earlier.
‫Let's say we don't have the age, so we only have the other information.
‫Now we could go ahead and create a human which doesn't have the age.
‫So let's say we don't have the age of Somalia.
‫We can get rid of that and we can run the code again.
‫So now it says, Hi, I'm Somalia and zero years old.
‫My color is blue and it writes zero because if an empty value is empty, like in our case H an integer
‫is empty.
‫It's just going to be default to zero.
‫So H is simply initialized to zero even if we don't initialize it.
‫So as you can see here, it says zero years old, even though we didn't enter anything.
‫So how can we solve that?
‫How can we fix that?
‫We could fix the whole introduce myself thing so we could say, okay, if somebody is or if there is
‫any age.
‫So let's say if age is not equal, zero.
‫Go ahead and write this one here.
‫I'm going to change this up a lot here.
‫So I'm gonna change it.
‫So if age is not equal.
‫Zero, right?
‫That and ls only introduce yourself with the first name, last name and color.
‫So get rid of H here and get rid of.
‫This one here with the years old.
‫So now let's run this again.
‫And we actually get an error.
‫Let me check, because I didn't change that value.
‫Okay.
‫Now we can run it again.
‫Now we see.
‫I'm Dennis.
‫Blah, blah.
‫That's fine.
‫I'm Amalia Panetta.
‫My eye color's blue.
‫So now amalia because there was no age given, is used or treated differently in a way that she introduces
‫herself differently.
‫And why is that useful?
‫Why would we have that?
‫Let's say you want to write a program which takes user data from a database and then it should do something
‫with that data.
‫So it should do some calculation or it should write some information to them or whatever.
‫So if you have all the information about that user, that's fine.
‫Then you can create a form and you can add all the information into that form and you can print it out
‫and send it to the person or whatever.
‫But what if you are missing some information?
‫So let's say you don't have the age.
‫Well, then you will simply not write the age onto the form.
‫But what if there is something more important missing like the address?
‫Why would you even print it out?
‫Because you cannot send it to that person.
‫So then you would write a different type of code.
‫So you could say, okay, I am collecting all the people that don't have an address and I'm doing something
‫else.
‫I'm checking Facebook for their name or something like that.
‫So the program would then check the Facebook API.
‫Is there a person with that first name and last name and age?
‫And then Facebook would give the information that the program could run some further investigation on
‫that person.
‫And that's some data sensitive stuff that I'm talking about here.
‫But in general, it's very useful to create constructors for with different information.
‫So we have one with four parameters, one with three parameters.
‫We can still create one with two or one with one.
‫So that's a little challenge for you.
‫Adjust the parameters so you have all the four cases or actually five cases.
‫So this is the default constructor.
‫Now please go ahead and create a different constructor for first name and last name, another one for
‫only first name.
‫And then of course adjust to introduce myself method accordingly.
‫All right.
‫I hope you tried it.
‫So what I'm going to do is I'm just going to copy that code here.
‫I'm going to get rid of the eye color.
‫That's it.
‫So that's the other constructor.
‫Now I'm going to copy that and I'm going to get rid of the last name.
‫All right.
‫And let's get rid of last name.
‫And now, of course, we need to adjust our method still.
‫So.
‫They introduce myself method.
‫So here we had the case when H was not zero and let's say last name is not equal now.
‫And what else do we have here?
‫I color is not equal null and finally our first name so we could have a different order.
‫But in the end it's fine.
‫So if all of those values are not equal null, then I want to go ahead and do this otherwise else if
‫I want to have a different check here.
‫So I'm going to copy this if here and I'm going to say in the next one, what if we don't have an equal
‫so we can get rid of this one and now let's copy that again.
‫And now we are lacking the H in general, so let's get rid of the H.
‫And now finally we have a version where we don't have a last name.
‫So now we of course need to adjust the statements.
‫So if we have first name and we have last name and we have the H and here we only have H, then we want
‫to write something about the H and I and so on.
‫So old.
‫So two years old.
‫Now we don't need that anymore.
‫Now.
‫That's if we have the age, if we have the last name and the first name, right?
‫So now we only have first name and last name so we can get rid of the whole color aspect.
‫And now finally we only have the first name, right?
‫So let's get rid of everything else except for the first name.
‫So now our introduce myself method is going to be clean and it's always going to inform us about exactly
‫what is available.
‫So let's say we create a new human and not a basic one, but let's call this human Nataly, that leap.
‫And she is a new human and we only have her first name.
‫And now, Natalie, please introduce yourself.
‫Maybe we should not use a capital letter here.
‫Natalie, introduce yourself.
‫And now we have one which has a last name.
‫So human.
‫And I'm going to call the Michael again.
‫Great name, new human Michael.
‫And it's not a human, but it's a human.
‫And this Michael is going to introduce himself and Michael should have a last name.
‫So I'm going to call a michael Miller.
‫And now the last version, human and we'll be frank, is a new human.
‫And it's Frank.
‫And this guy, he is called Walter, very funny last name.
‫And then he has an H.
‫So let's say he's.
‫Well, actually, we don't have that version.
‫We don't have the version where we only have the edge, but we don't have the color.
‫So that would be another constructor that we could create.
‫Actually, let's do that just because we can.
‫Let's create a different one.
‫I'm just going to copy.
‫Actually, I'm going to copy that one.
‫The parameter right here and I'm going to put it here, but I'm going to get rid of the I color and
‫I'm going to get rid of eye color here as well.
‫So now, of course, I had to adjust my introduce myself thing as well.
‫But here I want to make Frank 25 years old and I want Frank to introduce himself.
‫So now you see it's always the same.
‫We just need to adjust based on the parameters that we have available and then we just go ahead and
‫run the code.
‫So we are.
‫Hi, I'm Natalie.
‫Hi, I'm Michael Miller.
‫I am Frank Walter and 25 years old and so forth.
‫All right.
‫So now you have seen how to create multiple different constructors and you can see that we have a default
‫constructor which doesn't take any parameters.
‫And then we have different ones which have multiple different versions of amounts of parameters.
‫Great.
‫So now that you know that we should have a look at properties and they are super, super helpful and
‫useful and we will see how we can change values without having to make the variable public.
‫Because you have to be very careful with public variables of classes that you create because it can
‫be pretty tricky if you change those.
‫There can be a lot of security issues and if you not want to know more about that, I have a link that
‫I've shared with you.
‫You can just check that out and read in more detail what the purpose of using private here is and why
‫it's important.
‫So I'd say, see you in the next video where we are going to cover properties and yeah, have fun.