Hello, in this Java programming video, we are going to take a look at constructors. So we've got this class, before constructor is just a method that is run at the start of creating an object of the class. If we go here, we create two objects, T one and E two. So this is technically calling a constructor freedom, explicitly state or implemented construct that, you know, the compiler would just add one by itself, we can add our own so to the structure, no data type. So this can be a little weird. He's put the name of the constructor or I'm in the name of the class, because they will talk to code, bracket.
And that's it. So in here, it could be system Print alone. And I'm going to say and I run it, it says constructed twice. And if we go back, it's because those two enemies if nothing put one here, and I'll call it enemy free. There you go. It says constructed there, because it gets cold when we initially create an object isn't really powerful.
So in case you want to let us do some default setup, so instead of like doing equals 100, n equals one there, you could do in here for some message, you know, lotus flowers and settings for a class, all that stuff is really, really useful. So it's great for setting up your class. Let me go step further and actually show you How to do a constructor. But with with not a regular format like so, or actually gonna have his parameters, which you know, again are really useful as well. So this is, you know, similar to method overloading you can think of it like that it will it is an enemy. And if they do in quality I like so, maybe in here I'll do noise equals high.
That's pretty cool. Let's go to software systems Java. So we can pass in a value if we wanted because there's a constructor to handle that situation and if I were to do system and lm Put key free dot lawyers IE free prints at number seven. And that's because we passed in 75. You would pass enough it. It print out one.
If you go back to enemy live you set to one by default, the only place he gets changed is in this constructor. And that one will only get invoked if a integer is passed in. So who isn't this a positive nine, it will print out nine. So that's it that's constructed. If you have any questions, feel free to reach out and I look forward to seeing you in the next awesome Java video.