private
and writing public
methods in the class to set and get the values of variables.
Car
would be made up of Engine
and Steering
objects, and many more components.
To build the Car
class, one does not need to know how the different components work internally, but only how to interface with them; e.g., send messages to them and receive messages from them.
Car
class.
Abstraction | Encapsulation | Abstraction is a general concept formed by extracting common features from specific examples or the act of withdrawing or removing something unnecessary. | Encapsulation is the mechanism that binds together code and the data it manipulates, and keeps both safe from outside interference and misuse. |
---|---|
You can use abstraction using interface and abstract class.
|
You can implement encapsulation using access modifiers (public , protected , and private ).
|
Abstraction solves the problem in design level. | Encapsulation solves the problem in implementation level. |
For simplicity, abstraction means hiding implementation using abstract class and interface. | For simplicity, encapsulation means hiding data using getters and setters. |
I was playing chess with my friend and he said, “Let’s make this interesting.” So we stopped playing chess. — Matt Kirshen |