Explain the concept of abstracion and encapsulation with
one example. What is the difference between them?
Answer Posted / 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 |
Post New Answer View All Answers
Why is abstraction used?
What are the three parts of a simple empty class?
What is polymorphism explain its types?
What do you mean by abstraction?
What is an advantage of polymorphism?
What does I oop mean?
Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)
Why is there no multiple inheritance?
What is polymorphism oop?
What is polymorphism what is it for and how is it used?
Why do we need polymorphism in c#?
They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?
class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash
Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.
What is difference between oop and pop?