Definition of variables/fields type within a constructor, how is it done?

Posted by elementz on Stack Overflow See other posts from Stack Overflow or by elementz
Published on 2010-04-20T19:44:14Z Indexed on 2010/04/20 19:53 UTC
Read the original article Hit count: 229

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about java

Related posts about constructor