Welcome back.
In this video I want to show you optional parameters.
Now optional parameters are actually really cool.
What I mean with this is that if you want to make sure that an parameter when using an argument or entering
an argument is optional, so you don't have to add it, then you can do the following.
So let's say when we are setting the details in this method, we could say that by default the contact
number will just be Na.
So something like not available.
So when we are using the set details method now we can go ahead and just not use it.
Like not enter the contact number.
Let me show you how that works.
So let me save this class.
Let's go over to my program and let's go ahead and create a new customer.
So customer customer new customer I'm just going to use that default customer here.
So I'm going to just going to say customer dot set details.
And here I can go ahead and just say for example the name will be Dennis.
The address will be Main Street one.
And that's it.
So now you see I didn't even have to add the contact number.
So you see it's in square brackets, which just means it does have a default value assigned to it in
the method definition.
So here this is where we are defining our method.
And in here we said that contact number by default is going to be an A.
So here we're using default parameter contact number okay.
So this is how you can use default parameters.
Now the thing is you can use default parameters in constructors as well.
So we have this one constructor where we just had the name right.
So what we can say here is by default we're just going to assume that the what is it address.
Right.
So string address is going to be Na not available.
Right.
And the contact number is going to be not available either.
Like so now we get an error here.
That's because we already have a custom constructor that used all of those three parameters.
So you need to be careful.
Now obviously we could just say okay we don't need this one here anymore in that case.
So let me just paste that code in here.
And let's just say this entire custom constructor is not going to be required anymore, because now
we have a better one where we are using the name.
But then we're saying by default address is an A and contact number is an A as well.
So now when we are creating a new customer.
So let me create a customer.
Let's call this one customer one.
Now we can let's say we enter a name here.
So this will be will be frank.
And we're going to say customer one dot.
And let's say contact number.
Let's get the contact number of Frank.
All right I'm going to use a custom write line statement here.
Contact number of Frank or customer one whatever Frank is colon.
And then plus customer one dot contact number okay.
So now if we run this we will see that we get contact number of Frank is an A.
That's even though we never set it manually ourselves.
But the code just does that for us.
That's because we defined it here as an A or here.
In this case the contact number is set to Na.
So this here is a default slash optional parameter contact number as well as address okay.
Good.
So now that you've seen how default or optional parameters work let's look at how we can use named parameters.
They are also really cool.
So see you in the next video.