Well, im a little confused as to what exactly the terms Data Abstraction and Data Encapsulation mean:

This is what i read:

Data Abstraction:data abstraction is a process of representing the essential
features without including implementation details.

Data Encapsulation:: Data encapsulation, also known as data hiding, is the mechanism whereby the implementation details of a class are kept hidden from the user.

Can anyone please give me an example to exactly differentiate between the two?


7 Years
Discussion Span
Last Post by naaz.kaushik.3

Data Abstraction means something like this :

//Shape provides no implementation of the draw functions
//It abstracts the draw function from other shapes meaning that it
//defines functions that all type of shapes should necessarily have.
class Shape{
  public: virtual void draw()const=0;
class Ellipse : Shape{
 public: void draw()const{ API.drawEllipse(); }

Data Encapsulation :

class Info{
 string name;
 int uniqueId;
 string getName(){ return name; }
 int getId(){ return uniqueId; }

Notice that we do NOT provide public access for the variables name and uniqueId;
Instead we hide them or encapsulate them, and rather make a function that returns
a copy of them.

Edited by mike_2000_17: Fixed formatting


Thanks for the reply.

Can you please tell me if my understanding is correct:

Data Abstraction: we hide away the implementation details ie we do NOT show how a particular function is implemented.

Data Encapsulation:we hide data from other classes.

i have one more doublt:

class Sample {
             void doNothing();

Now, in the above example, we are hiding doNothing() method. What is this called as?
Is it still called as Data Encapsulation? (But we are not hiding data here)


>>Data Abstraction: we hide away the implementation details ie we do NOT show how a particular function is implemented

Thats exactly what data encapsulation is.

Data Abstraction means that we factor out common functions from a class and make a separate class thats abstract, so that the other classes can inherit form it.


Exactly in encapsulation access is restricted for the hidden data.Where as in abstraction no such rules exists......clearly abstraction is a process of hiding unnecessary implementation information from user.where as encapsulation is a process of hiding private implementation details from the public interface.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.