Can anyone tell me difference between Encapsulation and Abstraction? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can anyone tell me difference between Encapsulation and Abstraction?

8th Jan 2016, 4:33 PM
Digambar Bhujabal
Digambar Bhujabal - avatar
8 Answers
+ 14
I will explain u with an example, The class encapsulate every method in it that belong to it. Encapsulation can be understood by capsule which contain the medicine in itself. Abstraction is that the patient doesn't know about the medicine hidden in capsule. He just eat it as doctor says him.he had to no worry about the medicine inside the capsule. Thus in java encapsulation help us to abstract the inner layer from the end user. Hope it will make u understood.!!!
19th Jan 2016, 9:29 AM
Vikash Sahu
Vikash Sahu - avatar
+ 4
Encapsulation is binding the attributes and methods together inside a class. It is obtained through OOP, where inside a class the methods along with the datatype lie together leading to a complete behaviour. Abstraction on the other hand comes from the word abstract which deals with the user perspective. The user of the code need not know the internals or the working of your code and thereby should not have access to your variable which are essentially the properties of a class. It is achieved by using private, protected and public access specifiers. Generally, methods are kept public but member variable are kept private.
9th May 2016, 1:47 PM
Kalpak Seal
Kalpak Seal - avatar
+ 3
encapsulation tend to make a interface, abstraction tend to make structure of concepts
19th Feb 2016, 2:24 AM
Shaowei Zhang
Shaowei Zhang - avatar
+ 3
Encapsulation is about hiding the methods or inner workings of the object, while abstraction is about providing the user an interface where he uses inner methods without seeing them
4th Jul 2016, 5:01 PM
Crispus M. Shaki
Crispus M. Shaki - avatar
+ 2
Encapsulation is way of accessing data without exposing it. You can use getters and setters to save and retrieve variables. Abstraction makes the skeleton of the class if you make the function abstract, the subclass will have to override in their class.
19th Jan 2016, 4:24 AM
Umang Pandya
+ 2
Encapsulation is the process of methods and properties into a single unit. Abstraction is used to achieve Encapsulation.
8th May 2016, 11:46 AM
Pasupathy Devaraj
Pasupathy Devaraj - avatar
+ 2
encapsulation refers wrapping of data in single unit example like we create function and then we call it main so all matter is wrap up in function. abstraction refers to using essential feature without background details. eg when we make no of function in a class and then when we want a function that we need so we just call it by creating it object and calling the particular function at this time we used the feature abstraction
5th Jul 2016, 4:30 PM
yes in encapsulation we wrap up the whole data in one class or function i.e encapsulated in abstraction we hide the unnecessary details from the user
6th Feb 2016, 4:21 PM