Definition of variables/fields type within a constructor, how is it done?
- by elementz
I just had a look at Suns Java tutorial, and found something that totally confused me:
Given the following example:
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
Why is it, that the types of the variables (fields?) gear, cadence and speed do not need to be defined?
I would have written it as follows:
public Bicycle(int startCadence, int startSpeed, int startGear) {
int gear = startGear;
int cadence = startCadence;
int speed = startSpeed;
}
What would be the actual differnce?