What is the difference between encapsulation and datahiding.explain with example

Showing Answers 1 - 70 of 70 Answers

viswanathareddy

  • Nov 24th, 2005
 

Hi,

Please give me the detail explanation on the Encapsulation and Data hiding with example.

  Was this answer useful?  Yes

It is the mechanism that binds together code and data in manipulates, and keeps both safe from outside interference and misuse. In short it isolates a particular code and data from all other codes and data.

ex:

Class Base

{

int a=1;

Public void fun1{}

}

Abt data hiding,we access the data from a class in a secure way using the object.

  Was this answer useful?  Yes

zahoorahmad

  • Apr 12th, 2006
 

Encapsulation:

when u used format specifiers, public, private and protected. Basically u r defining scopes so encapsulating them.

Data Abstraction:

But when once u have made ur porgram, you dont give ur code to ur user but exe. so here ur hiding ur data .. this is often said as data abstraction.

so as a recall

PRIVATE PUBLIC = encapsulation

EXE not CODE = data abstraction.

  Was this answer useful?  Yes

Milind

  • Apr 20th, 2006
 

Hey....

Can we say that we can achieve data hiding with the help of encapsulation...?? please correct me if I am wrong....

  Was this answer useful?  Yes

Kumar nitya nand

  • May 5th, 2006
 

Deasr Sir/Madam

I m requesting u that please mail answer of some certain Question.

what is the difference between encapsulation and Abstraction.

How can we change the value type to reference type.

regards

Nitya

  Was this answer useful?  Yes

malathi

  • May 27th, 2006
 

Encapsulation is the inclusion all the resources needed for the object to function - basically, the method and the data.

information hiding is one technique used to accomplish encapsulation of an object.Information hiding is when you remove data, methods or code from a class's public interface in order to refine the scope of an object.

 

  Was this answer useful?  Yes

vsd123

  • Jul 27th, 2006
 

In simple terms, Encapsulation is am implementation of the data abstraction(data hiding). Data hiding is conceptual while encapsulation is how u implement that concept logically.

 

  Was this answer useful?  Yes

ENCAPSULATION : WHEN IS ARE DECLARING A CLASS WE ARE DOING ENCAPSULATION.

DATA HIDING: WHEN WE PROVIDE ACCESS SPECIFIER TO THEM LIKE (PRIVATE PROTECTED,PACKAGE PROTECTED, PUBLIC) WE ARE HIDING THE DATA FROM MISUSE.

PLEASE COMMENT...

  Was this answer useful?  Yes

Binta Ceesay

  • Dec 22nd, 2006
 

 what is the difference between encapsulation and datahiding.explain with example

  Was this answer useful?  Yes

Aneena mathew

  • Jan 2nd, 2007
 

Data encapsulation is the most striking feature of a class.It isolates a particular code and data from all other codes and data.

Hiding means insulation of data from direct access by the program.

  Was this answer useful?  Yes

mathan

  • Feb 6th, 2007
 

hi dear.,Abstraction, information hiding, and encapsulation are very different, but highly-related, concepts. abstraction is a technique that helps us identify which specific information should be visible, and which information should be hidden. Abstraction can be (and often is) used as a technique for identifying which information should be hidden. For example, in functional abstraction we might say that it is important to be able to add items to a list, but the details of how that is accomplished are not of interest and should be hidden. Using data abstraction, we would say that a list is a place where we can store information, but how the list is actually implemented (e.g., as an array or as a series of linked locations) is unimportant and should be hidden. Encapsulation is then the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible. ------------------------------- Confusion can occur when people fail to distinguish between the hiding of information, and a technique (e.g., abstraction) that is used to help identify which information is to be hidden. -----------------------------------"[Information hiding is] the principle that users of a software component (such as a class) need to know only the essential details of how to initialize and access the component, and do not need to know the details of the implementation." check this link http://www.itmweb.com/essay550.htmu ll definitely get a clear idea about Encapsulation Data Hiding Abstraction...........

d2

  • Apr 8th, 2007
 

Abstraction - This term is used when you have a hierarchy of classes with an abstract class(interface in langauges other than C++) on top. An abstract class tells the users(developers who use the systems with the help of hierarchy) what methods they can call. Ofcourse only public members are accessible to the users.

Encapsulation - This is the actual implementation of the abstract class. Now you can have a hierarchy with various classes and their subclasses implementing the interface. However, to the user.. its only the abstract class that they can call ur system with.

Data Hiding - This comes at the private/protected/public level of access modifiers.


I believe the difference between these terms become more clear when you look from other languages than C++ as C++ doesnt have anything as interface.

  Was this answer useful?  Yes

balaji

  • Aug 21st, 2007
 


Encapsulation is nothing but binding both data members and member functions that operates on that data into single entity called Class. so that One object's data is separated from other object so that is called as Data Hiding that can be achieved using access specifiers. 

  Was this answer useful?  Yes

vikram123

  • Jul 14th, 2008
 

But when once u have made ur porgram, you dont give ur code to ur user but exe. so here ur hiding ur data .. this is often said as data abstraction. so as a recall PRIVATE PUBLIC = encapsulation EXE not CODE = data abstraction.

  Was this answer useful?  Yes

invadernit

  • Jul 17th, 2008
 

Encapsulation is a technique of combining the "data" and the "code" which acts on data, whereas datahiding is just protecting the data from direct outside access.

Example:

class MyClass
{

private string name = "Nitin";
private int age = 26;

public string GetDetails()
{
 retrurn "My name is "+ name +" and I am "+age+ " Years old";
}

}

here,

MyClass is encapsulating two members and a function


and any outside object cannot access "name" and "age" directly

  Was this answer useful?  Yes

ajitgag

  • Aug 5th, 2008
 

Encapsulation => Data + member in a Class. not necessairly Public private.
Abstraction =>  Data + member in a Class. But hide the data that you dont want to use outside the class.  make the things private that you dont want to show to client...

  Was this answer useful?  Yes

Encapsulation: It is a concept in which we group together all the data members and member methods together like different medicines putted together in a single capsule.
So, our java class is an example of encapsulation.

Data hiding: It comes from the concept of encapsulation in which we try to hide the all the information within the class from outside the class. It is basically used for the security purpose in which we try to protect the data members of consistency. that is, making it difficult to change the consistent data directly from outside the class.
Also, try to make it difficult for users that what the class is using so that it will be difficult to change function of the methods from outside.

Data abstraction: Simply, hiding the unnecessary information. So, we show only what we can do with the class instead of how does it work. Very common example is the Car class. where we can use the class without knowing the detail of the car i.e. detail of the engine used in the car, or other information like gear making company. here we only use the engine with knowing how much horse power it is, and how many gear it has.

shamli85

  • Apr 2nd, 2010
 

Creating a Class is an example for encapsulation. Here we are making the data and related actions (or methods or functions) into a single "capsule". Or I wud say we are encapsulating the data with related functions.


A better exaple for data hiding would be a Java been. Here we are hiding the member variables by making it private. And we are giving the access to them thru setters and getters which are public.

The word abstraction is also could be confusing. It is nothing just hiding the complexities. A private method which is called inside a public method of the same Class with a heavy business logic could be considerd as an example of abstraction.

Please correct if I am wrong...

  Was this answer useful?  Yes

The encapsulation is methodology that helps hide internal data of a class.

So, why we need hide information ? this is so simple, we make a class information covered because you need know how works some object that's encapsulated and you as user an object, don't need  know how much functions have an object or how much property have an object, you know that object have input and output, when you insert A object returns B.

Data Hiding is process, that uses encapsulation methodology. hide property and methods is data hiding.

So, process usage an object, is called as Abstraction. when you using an object, that is abstraction because encapsulation leaves open spots, that's need to using object that is abstraction.

  Was this answer useful?  Yes

sundar

  • Jul 22nd, 2011
 

encapsulation is collection of objects in a single classes.
data hiding(or)data abstraction is giving main details of the data without showing all details of the data.

  Was this answer useful?  Yes

RAMAN

  • Sep 4th, 2011
 

Data encapsulation is the process of binding data members and member functions that manipulates that data. It keeps the data from external interference and misuse.
Data hiding is the process of hiding data from the other classes. We can hide the data by using address specifier private and protective.

  Was this answer useful?  Yes

srilakshmi

  • Sep 7th, 2011
 

encapsulation means wrapping up of data into a corresponding memberfunctions into a single unit.where as datahiding means to hide the data

  Was this answer useful?  Yes

Ravindra

  • Dec 12th, 2011
 

Encapsulation means to bind the data and functions into a single unit.OOPs treated data as an object, its primary deals with security of data rather than procedure.Wrapping Up of data in a single unit is known as Encapsulation.

Data Abstraction is the process of defining only the essential features without explanation of background.
e.g: "Switch Board" in which we just see the Switch not their connectivity to the Wires........

  Was this answer useful?  Yes

ranju

  • Dec 19th, 2011
 

The process of binding data and function is encapsulation the process of hiding the data from direct access by the program is data hiding.

  Was this answer useful?  Yes

eswaran

  • Jan 4th, 2012
 

Enacapsulation is bing the data type and member function into a single name called class name.

for example:
Consider this code:

Code
  1. class a

  2. {

  3. private:

  4. int a;

  5. public:

  6. void a();

  7. }


The above code called encapsulation

Data hiding in which the properties of class members are hide outside the class.

for example:

Code
  1. class a

  2. {

  3. private:

  4. int a;

  5. public:

  6. void a();

  7. };


The above code int a; declared inside the private block so we dont use outside the class.

  Was this answer useful?  Yes

Deepu

  • Jan 4th, 2012
 

Wrapping up of data and function in a single unit is called encapsulation.

  Was this answer useful?  Yes

shrimanta

  • Mar 14th, 2012
 

encapsulation is the concept of the datamember. Data Hiding is the Access Specifier.

  Was this answer useful?  Yes

prabhjot kaur

  • May 12th, 2012
 

encapsulation is the wrapping up of data members and data functions into a single unit like classes. here we can control the visibility of data with the help of access specifiers i.e. public,private and protected.
in data hiding data is totally private we cannot access the data.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions