0

What is the difference between abstraction and encapsulation in java?

Please anyone explain it in laymen terms with examples

4th Aug 2019, 3:20 PM
Geek
Geek - avatar
1 Resposta
+ 12
1) The most important difference between Abstraction and Encapsulation is that Abstraction solves the problem at the design level while Encapsulation solves its implementation level. 2) Abstraction is about hiding unwanted details while giving out most essential details, while Encapsulation means hiding the code and data into a single unit e.g. class or method to protect inner working of an object from the outside world. In other words, Abstraction means extracting common details or generalizing things. 3) Abstraction lets you focus on what the object does instead of how it does, while Encapsulation means hiding the internal details of how an object works. When you keep internal working details private, you can change it later with a better method.  For example, when you first describe an object, you talk in more abstract term e.g. a Vehicle which can move, you don't tell how Vehicle will move, whether it will move by using tires or it will fly or it will sell. It just moves. This is called Abstraction.
4th Aug 2019, 3:37 PM
Shadow Ninja[#Inactive]
Shadow Ninja[#Inactive] - avatar