Explain the concept of abstracion and encapsulation with
one example. What is the difference between them?
Answers were Sorted based on User's Feedback
Answer / purba phalguni mishra, gandhi
ENCAPSULATION->
* It is a mechanism which unites the code and the data it
manipulates.
*It keeps them safe from external interference and misuse,
thus enforcing the separation between specification and
implementation of ADTs. Hence it enables the debugging of
program easily.
DATA ABSTRACTION->
* It is the creation of new data types [ADTs] using
encapsualted-items that are well suited to an application
to be programmed.
* It is a powerful technique resulting in optimal, more
readable and flexibles programs.
*******U r most welcome to challenge with my answer*****
Is This Answer Correct ? | 9 Yes | 2 No |
Answer / naveed
Abstraction refers to the act of representing essential
features without including the background details or
explanations.
Encapsulation is the procedure of covering up of data and
functions into a single unit (called class).
FOR EXAMPLES AND MORE INFO GOTO :
public class School
{
private string Schooldepartname;
public string SchoolDepartname
{
get
{
return Schooldepartname;
}
set
{
Schooldepartname =value;
}
}
}
public class Departmentmain
{
public static int Main(string[] args)
{
School d= new School();
d.SchoolDepartname="Communication";
Console.WriteLine("The Dept. Name is :
{0}",d.SchoolDepartname);
return 0;
}
}
From the above we can see the use of Encapsulation by using
properties. The property has two accessor get and set. The
get accessor returns the value of the some property field.
The set accessor sets the value of the some property field
with the contents of "value". Properties can be made read-
only. This is accomplished by having only a get accessor in
the property implementation.
Abstraction
Any function having lines of code we dont need the code of
function ie hiding detail but we know that what result we
are getting ie (showing essential )
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / aarti ashar
(1)Abstraction:
To implement real world entity into program. Class uses the
concept of abstraction.
->abstraction is a process of mimicking a behavior.
->Simplifying complex reality by modeling classes
appropriate to problem.
->Abstraction is a process that involves identifying the
crucial behavior of an object and eliminating irrelevant
and tedious details.
(2)Encapsulation:
->Binding the data and code to access that data.
Encapsulation only refers to a container which has a data
and its related functions in it.
->When an objects state and behavior are kept together they
are encapsulated. The data and the methods that manipulated
that data are stored together in cohesive unit.
Is This Answer Correct ? | 3 Yes | 4 No |
How to use CMutex, CSemaphore in VC++ MFC
diff between Abstract class Interfaces?
What is abstraction example?
what are the ways in which a constructors can be called?
What are the three main types of variables?
i=20;k=0; for(j=1;k-i;k+=j<10?4:3) { cout<<k; } //please comment on the output
what is the virtual function overhead, and what is it used for ? i hope i can get and appropriate answers, thanks a lot....
write a program to print * * * * * *
What is destructor in oop?
WRITE A SIMPLE C++ PROGRAM TO SWAP TWO NOS WITHOUT USING TEMP
why destructor is not over loaded?
Can we have inheritance without polymorphism?