when you run the following code, the gear value for bike1 changes to 3 as well as bike2. Can you explain why? My own guess is because bike1 and bike2 are object variables and don't actually contain any values, they're just references (labels). When they're assigned equal to each other they both change to 3. Am I right?
class Bicycle{
int gear = 0;
void changeGear(){
gear = 3;
}
}
public class BicycleApp {
public static void main(String[] args) {
//Create bike 1
Bicycle bike1 = new Bicycle();
System.out.println(bike1.gear);
//Create bike 2
Bicycle bike2 = bike1;
System.out.println(bike1.gear);
//Call the method
bike2.changeGear();
System.out.println(bike2.gear);
System.out.println(bike1.gear);
}
}