What is the difference between assigning a parameter to an instance variable? Why is it wrong when you write the parameter before the instance variable?
int variable;
void set(int parameter)
{
variable = parameter;
parameter = variable;
}
Case 1:
int variable;
void set(int parameter)
{
variable = parameter;
}
Case 2:
int variable;
void set(int parameter)
{
parameter = variable;
}
Both cases are correct by Java syntax, but case 2 has very little logical value...
The case 2 method parameter has a value and we need to use it. but before using this value, we change this by assigning variable, so we lost the previous value.