Where in your classes source code should you put the constructor(s)?
I use the following:
package statement ....
import statements....
public class MyClass {
// instance attributes
private int i;
// class attribute
private static int MAX;
// static methods
public static int getClassCount() {
}
// Constructor!! at lest.
public MyClass() { // constructor.
}
// public methods
// protected methods
// private methods
// public static void main
}
But they can go anywhere. I feel it is better yo put things in order of visibility. For instance I rather have the public methods before the private methods ( so if I'm looking for an specific public method I know it's at the top of the file ) For the same reason I usually put the constructor at the top.
Are these arguments the names of the variables?:
Not necessary, you can name them as you want. I usually use the same name.
...or are gear, cadence and speed the names of the variables?...
They are the instance variable names
What is the difference between (int startCadence, int startSpeed, int startGear) and gear, cadence and speed?
The first are the parameter names for the constructor and the former are the names of the attributes of the object it self.
Take this other sample:
public class Person {
private String name; // a person has a name.
public Person( String nameParameter ) {
this.name = nameParameter;
}
public String toString() {
return "My name is : " + this.name;
}
public static void main( String [] args ) {
// creates a new "instance" and assign "Patrick" as its name.
Person one = new Person("Patrick");
System.out.println( one ); // prints "My name is: Patrick"
// each person have its own name.
Person two = new Person("Oscar");
System.out.println( two ); // prints "My name is: Oscar"
}
}
As you see, when you pass a value to the constructor you're using an argument, and when you see the constructor code you see the parameter name ( which receives that argument ) and then it is assigned to the instance attribute.