In java why is it bad to set a field with both setter and getter as public?
Consider the following Java code:
public class SomeClass{
private int data;
public void setData(int data){
this.data = data;
}
public int getData(){
return this.data;
}
}
In the above code the value of data can be accessed from anywhere. So why
not just make the field data public?
No comments:
Post a Comment