Hi this is so hard.
Once again welcome to the next video.
All this object oriented programming in case of Cartland.
Now in the previous video we learned about the properties primary constrictors in a blog and so on.
Now in this video let us know.
Check out the concept of secondary constrictors in case of Cartland.
So unlike Java in case of Codlin we have the concept of secondary constructors as well.
So here what we do is inside the same application that we created in the previous VDU inside the class
of student.
What we do is I would simply declare a secondary constructor.
Now to declare a second constructor you have to simply use the keyword of constructor followed by simply
defined update on Wieters.
Now if you are declaring that secondary constructor.
Then make sure you give an explicit call to this primary constructor as well because the compiler won't
allow to write such code without calling this primary constructor from the secondary constructor.
No what I mean is you have to simply declare such as name string and then let us use the Demetre of
ID.
Let's see in now followed by a colon followed by a simply give a call to this primary constructor by
simply passing the name right.
And now unlike the primary constructor the second constructor has its own body so the primary constructor
does not contain its own body.
But you can treat this in a blog as a part of this primary constructor that we saw in the previous value.
So this second preconstructed has its own body.
And here you have to simply call this primary constructor because without calling this primary constructor
Let's see what happens.
It simply shows some error.
The primary constructor call is actually expected.
So with the help of this keyword you can simply call this primary constructor that will simply instantiate
this field variable of name.
Now it is not mandatory to keep this name and this name as.
You can also call it let's see.
And so here.
Simply give a call to and right now correctly if you notice this ID is just acting as up.
Then we go inside the secondary constructor.
Unlike this name which is actually the part of the class and behaving as a property of the class.
But this is not the property of the class.
So far that latest append that keyword.
And let's see what happens.
So the intelligent ID is showing that that on the second constructed is not allowed as a parameter.
So in Gartley you can not declare the properties inside the secondary constructor unlike the primary
constructor where you have declared name as a property of the class.
So this VAD or Val is not allowed inside the secondary constructor.
So what is the solution for this.
So for this we have to simply declare that Id equal to c minus one.
This is our default value assigned to this ID.
Now let's just declare though type of type.
Let's see in.
So now we have simply defined the property of the student as that ID is equal to minus 1 which is again
their default value.
So inside the body of the second constructor we can simply use this keyword.
This dog i.e. equal to the incoming ID.
And now you can access this ID inside the block.
And now inside the main method you can simply use student object door ID and simply print the ID of
the student.
There does use the print keyword and let us know.
Also pass this coma and not previously when the statement was getting executed.
It was simply going to call this primary constructor.
But suppose if you have got the value of the student id then in that case simply call the secondary
constructor and by simply passing to it meters like say the ID of the student is now then.
So when the statement will be executed it will simply call this second preconstructed where N will get
the value of student and this ID will not be done and explicitly we are calling the primary constructor
simply pass the value of a string that will be now stored inside of that name.
And then we will print the statement as student has got a name as string and inside the secondary constructor
we are simply initializing property of ID as ID.
And now here.
I'm simply painting the student ID.
Let us note in the chord
and not in the output.
And so you can see student has gotten the name as she and and this is the idea of the student.
Now you must be thinking why did not I bring the student ID inside the upper end Elena statement.
We didn't.
And it mattered little ride this out as well.
Let's see.
An 80 is dollar ID.
Let us know in the court again.
And now this time I have simply got this outward student has got the name string and the ID is minus
one.
And right after this statement when this student is executed we are getting the fake ID ESTAN.
Now why this is being rendered as minus 1 which is actually their default value of the ID.
Now what happens is that when this statement is executed.
Student Cherian.
And so what happens is that it's simply called the second preconstructed.
Now this second three constructor simply called this primary constructor which in turn simply execute
this statement in a block.
Now right after the block is executed this statement is executed.
Right.
So Windus 80 has got the value of 10.
But before that this statement was already exec you dead where the ID was minus one.
So here you can simply write a command line.
The body of the secondary constructor is scored off the block.
So that is why the value of the ID is minus 1 instead of 10.
So always remember this so are the end of this video.
Let us embrace in this video we learn about the second constructor and also we cannot declare the property
like that space inside the second reconstructed.
And if you're declaring the second constructor then you must give a call to the primary constructor
like we have done here.
And this will simply called this constructor present here which is actually the primary constructor.
Fine.
So here let us remove the school from here which is of no use.
So this was all about this video.
Thanks for watching and have a good day.