Java Constructors- Assigning value to variable

constructor, java

Solution

If you declare the variable in your constructor, it will be local to the constructor and not visible anywhere else in your class.

Problem

Is there a difference between assigning values to variables outside of any method, and assigning these values within a constructor? Looking at Oracle's Java tutorial, they have: ``` public class Bicycle { int cadence = 0; int speed = 0; int gear = 1; void changeCadence(int newValue) { cadence = newValue; } ``` is this any different from saying/why didn't they just say: ``` Bicycle(){ int cadence = 0; } ```

Original source