GeekInterview.com
Series: Subject: Topic:
Question: 77 of 85

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

Asked by: Interview Candidate | Asked on: Nov 2nd, 2005
Showing Answers 1 - 30 of 30 Answers

encapsulation is the concept of grouping of datamembers and member functions.Data hiding means we cannot use the datamembers out side of the class.

  
Login to rate this answer.
viswanathareddy

Answered On : Nov 24th, 2005

Hi,

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

  
Login to rate this answer.

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.

  
Login to rate this answer.
zahoorahmad

Answered On : Apr 12th, 2006

View all answers by zahoorahmad

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.

  
Login to rate this answer.
Milind

Answered On : 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....

  
Login to rate this answer.
Kumar nitya nand

Answered On : 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

  
Login to rate this answer.
malathi

Answered On : 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.

 

  
Login to rate this answer.
vsd123

Answered On : Jul 27th, 2006

View all answers by vsd123

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.

 

  
Login to rate this answer.
RAJEEV16706

Answered On : Sep 8th, 2006

View all answers by RAJEEV16706

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...

  
Login to rate this answer.
Binta Ceesay

Answered On : Dec 22nd, 2006

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

  
Login to rate this answer.
Aneena mathew

Answered On : 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.

  
Login to rate this answer.
mathan

Answered On : 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...........

Yes  1 User has rated as useful.
  
Login to rate this answer.
d2

Answered On : 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.

  
Login to rate this answer.
balaji

Answered On : 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 DataHiding that can be achieved using access specifiers.

  
Login to rate this answer.
vikram123

Answered On : Jul 14th, 2008

View all answers by vikram123

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.

  
Login to rate this answer.
invadernit

Answered On : Jul 17th, 2008

View all answers by invadernit

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

  
Login to rate this answer.
ajitgag

Answered On : Aug 5th, 2008

View all answers by ajitgag

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

  
Login to rate this answer.

Data hiding is done by using access specifier and data encapsulation is wrapping of data which use default specifier.

  
Login to rate this answer.
anupprakash36

Answered On : Mar 23rd, 2010

View all answers by anupprakash36

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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
shamli85

Answered On : Apr 2nd, 2010

View all answers by shamli85

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...

  
Login to rate this answer.

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 informationcovered 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 encapsulationleaves open spots, that's need to using object that is abstraction.

  
Login to rate this answer.
sundar

Answered On : 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.

  
Login to rate this answer.
RAMAN

Answered On : 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.

  
Login to rate this answer.
srilakshmi

Answered On : 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

  
Login to rate this answer.
Ravindra

Answered On : 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........

  
Login to rate this answer.
ranju

Answered On : 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.

  
Login to rate this answer.
eswaran

Answered On : 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.

  
Login to rate this answer.
Deepu

Answered On : Jan 4th, 2012

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

  
Login to rate this answer.
shrimanta

Answered On : Mar 14th, 2012

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

  
Login to rate this answer.
prabhjot kaur

Answered On : 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.

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.