Hello and welcome to the goal and programming language course in the conversation we talked about Method
can accept both points from value in decision.
We want to talk about the other this concept.
Assign different value for a struct field.
Method of assigning to custom default value can be achieved by using constructor function instead of
creating a strong directory.
We create a function can be used to create an struggled with the cost and default value for this distronic
feats.
Let's go to this good program to illustrate how to assign defined value for restaurant field.
First, create a strike named A-student, tie this to the restaurant called Graisses and define fields
for this strike.
Name is string and age.
It set the common above the established name for exporting, this student stressed.
Still, there are strict.
Now, create a metal for a student assignment name instance to set default value for a student feels
fine.
Set a receipt for a student as strong as S s as trees.
The student named for this metal, for example.
Instant, curly brackets.
In this case, set the default value for two fields, name and age.
If that name equals equals, no
less name equals rather than if it's the age.
Equals equals zero is that h equals twenty five.
The compiler checks if the field values are and so assigns, the value defined in this method as defined
values, voting set a comment for this method as export in turn
metals reform as they call, then save that provision.
Now, go to main function and create instances of student astrong and initialize value.
First, declare an instance and mete out assigned value is to that point where calling equals.
A student now invokes the instant method for initializing default values.
This student won't even stand up and display these students, right?
If
the student one
second declare another student instance and just initialize name value for it and don't assign any value
for each bit, go to the next line is to do that.
Two column equals the student and set name.
Julia?
Student to go out and stand and display this, a student in the strike as the student to and to declare
another student in the stands and just initialize a value for it and don't assign venue for name field,
go to the next line.
Define the variable light.
Student three column equals the student and said just age by the age, for example 30 and involve the
instant method student.
Treat these Typekit.
Go to the next line and display this a student.
If the student three reformat the code, save the project and execute the program.
Now we can see the output for students want.
We don't have initialize a student.
So after invoking Mr. Smith to the name and age fields value set to define value.
Means Robert and Tony fine for student two.
We don't have initialise age field, so after we walk ins transmittal the age feed value set different
value means Julia and twenty five and four student three.
We don't have initialise name field, so Anthony won't Mr. Smith, with the name field value set to
default value means Robert and Turkey, so he could assign default value for this tournament via a method.
OK.
In order not to prolong the time of decision, we will finish it and we will continue the content in
the next session.
Goodbye.