- #1
prosteve037
- 110
- 3
In class the other day, my professor had written this as part of the lecture notes:
Thus, this definition was mentioned as part of methods. He then went on to show an example of this as in the following:
Now this is not a method definition, but rather a constructor definition. What I'm trying to understand is what the difference is between the two (if there are any).
Also, to be even more specific, the underlined bold parts are what confuse me. If a parameter of a method is a local variable that initially doesn't have a value until called on, why is the variable declaration in the parameter list needed?
In the given example, we wanted to associate the "Dog" class with the "Collar" class. But I don't understand what's going on with the parameter "Collar _collar". Why is this, along with the "_collar = collar" declaration, necessary?
The parameter list is a (possibly empty) list of parameter declarations. Recall that a parameter is simply a local variable whose initial value is provided by the corresponding argument in the method call. If more than one parameter is declared in a method's parameter list, a comma ',' is used to separate the declarations. The parameter list is delimited by parentheses, '(' and ')'.
Thus, this definition was mentioned as part of methods. He then went on to show an example of this as in the following:
Code:
public class Dog {
private Collar _ collar;
public Dog(Collar collar) {
_collar = collar;
}
}
Also, to be even more specific, the underlined bold parts are what confuse me. If a parameter of a method is a local variable that initially doesn't have a value until called on, why is the variable declaration in the parameter list needed?
In the given example, we wanted to associate the "Dog" class with the "Collar" class. But I don't understand what's going on with the parameter "Collar _collar". Why is this, along with the "_collar = collar" declaration, necessary?
Last edited by a moderator: