To reduce confusion:
Encapsulation is used to hide information or hide data.
Encapsulation means on its own . All objects in Java have a set of data and methods for working with this data. Therefore, the user of any object does not need to worry about how the object works. Thus, you hide information and other difficulties.
: Java- , .
. , , specfic- , , .
:
class Animal {}
Lion Animal {}
, Lion , .. Animal.
givien KepaniHaole .
:
public interface Animal{
public String getType();
}
class Lion implements Animal {
private String animalType = "WILD";
@Override
public String getType() {
return this.animalType;
}
}
class Cow implements Animal {
private String animalType = "Domestic";
@Override
public String getType() {
return this.animalType;
}
}
Lion Cow Animal. Lion Cow override getType Animal.
- , . , , , Animal, getType, , .. .
, , animalType Lion Cow, , , .
getType, . .