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.
Q: Which of the following is a good programming practise
1: Declare all variables globally
2: provide comments to each statement of the program
3: function modifies its parameters
4: none of these
options 1 and 2 definitely not correct.
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.
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..
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?