My question is if we can access the variables (data) though via getters and setters, how come data is hidden or safe?
You can encapsulate the logic under getters/setters. For example,
public void setAge(int age) {
if (age < 0) {
this.age = 0;
}
else {
this.age = age;
}
}