Answer:
Since you have not mentioned the way toString method was implemented in your class, I am just providing a sample implementation of it.
Please find the code in file attached.
Explanation:
Please see attached file.
<h2>Only when the default parameter are defined in the function</h2>
Explanation:
Answer is same for both the question.
- A default argument or default parameter is assigned an automatic value when the function is invoked.
- So the default value will be assigned during the function definition itself.
- You can find the assignment operator which is being used in the function definition.
- You can overwrite the default values by passing your own value in the calling portion
- The constraint here is that, the default parameter should always be the last parameter of function definition to avoid ambiguity.