Amazon Interview Question
Software EngineersCountry: United States
Interview Type: Phone Interview
Don't provide public methods that will change your object.
In case of modification, return a new instance.
Prefer to declare your variables as final.
Process everything needed in the constructor.
Example:
public class DoTheMath {
private int x;
private int z;
public DoTheMath(int N) {
calculate(N);
}
private void calculate(int N) {
// code code code
}
public int getX() {
return this.x;
}
public int getZ() {
return this.z;
}
}
Make your class and instance variable as final, your class will be immutable.
- Suri February 09, 2017