Encapsulation vs. Inheritance vs. Abstraction
- Encapsulation:
This process hides a class
's or object's public or external variables and methods from users. These variables and methods are only available to the class
or object's creator. It safeguards data that is specific to each object layer within a system. Users have no access to these private variables or methods.
- Inheritance:
Is a logical concept that extends the concept of encapsulation to multiple objects. In Java
, the inherit keyword can be used to add new functionality to a class
's base class
.
- Abstraction:
Is a method that allows programmers to concentrate their efforts on only one "layer" of their programs at a time. These layers are also known as objects that are separated from one another. Abstraction keeps code manageable and ready for testing before moving on to the next layer of the program.