2009-11-08 19:46:03 UTC
the constructor has a parameter which is to be assigned to the member variable in the simple fasion: memberVariable=parameter;
the difference between these two examples is in how the parameter is assigned to the member variable. One uses the "this" function, and the other uses different variable names for the parameter and the member variable.
My question is: which of these examples is correct? If they both would work, then which one is better programming?
class Person{
public Person(int age){
this.age = age;
}
private int age;
}
class Person{
public Person(int inputAge){
age = inputAge;
}
private int age;
}