If I don’t include this references in the constructor, I get the error "The assignment to variable [x] has no effect java." However, I have no problem not using one in the get method written below. Why is that?
public class Bicycle {
private String brakeType;
private int numGears;
private int numWheels;
// Constructor
public Bicycle(String brakeType, int numGears, int numWheels) {
this.brakeType = brakeType;
this.numGears = numGears;
this.numWheels = numWheels;
}
// Get methods
public String getBrakeType() {
return brakeType;
}
>Solution :
To differentiate between the parameter and the instance variable