I think most people find it bad practice to change the value of a parameter inside a method. That's because it makes it more difficult to understand the code in the method. Programmers generally expect that the parameter variables that are passed to the method, contain the values that we passed to the method when it was called. If, somewhere inside a method, you change the value, then it makes it harder to follow what value exactly the parameter variable has at any point in the method, making the code hard to follow.
shruti dighe wrote:Jesper de Jong .. Please help me select the right answer for this question
This looks like a homework question to me, and here we like you to DoYourOwnHomework (←click).
My suggestion: Post what you think the answer is, AND your reasons for choosing it. Then we might be able to help you.
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Joined: Jan 22, 2013
function are written to perform some task .. it is obvious they will change the parameters when it comes to calculations performed inside that function. How can it be a bad programming practise then ?
in that case then all variables in java would have been declared final . and the "printstacktrace" method can always give the stack condition in case of exception..
Parameter variables are used to hold the value passed from the calling function. Considering your question about calculated results, you can always have method local variables that holds the calculated results. Correct me if I am wrong.
shruti dighe wrote:function are written to perform some task .. it is obvious they will change the parameters when it comes to calculations performed inside that function...
It is? Then why does Java allow you to put the qualifier final on a parameter? I think you're confusing using values to perform a calculation, which may indeed produce a different value, and changing those values.
And you still haven't answered the question: What do you think the answer is, and why?