I am new to Java and I would like too know how to properly assign values inside a constructor with parameters. The issue is how to properly encapsulate the values, i.e. do we use set
methods or is just using the this
keyword enough? Please note I am asking about encapsulation and OOP.
public class cars{
private String make;
private String model;
public String getMake(){
return make;
}
public String getModel(){
return model;
}
public void setMake(String ParamMake){
this.make = ParamMake;
}
public void setModel(String ParamModel){
this.model = ParamModel;
}
// Should it use the setter
public cars(String make,String model){
setModel(model);
setMake();
}
// Or
public cars(String make,String model){
this.model = mode;
this.make = make;
}
}