By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

abstraction polymorphism nd encpsulation

P: 1
please tell me about abstraction polymorphism and encapsulation and with simple code example and solution
thanks
Oct 23 '15 #1
Share this Question
Share on Google+
2 Replies


P: 16
Abstraction:
you hide unnecessary details from the user.The user only has to know what he needs to know.For example,when you use the sqrt() function,you have no idea of what is happening behind the screen.All you need to know is that,if you pass a number to sqrt(),it will return the square root of the number.The logic used in finding the squareroot is hidden from you.
Polymorhism:
The ability of something(usually functions) to processed in more than one way.For example,there can be two functions called area().One to find the area of a circle and the other to find the area of a triangle.The compiler knows area() can be processed in two different ways.
Oct 23 '15 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
OK let's try this again.

Encapsulation occurs when you surround your data and your methods in a class (or struct). The idea is that if there is a bug, or some other change required, it will be done inside the class (or struct) rather than all over the code base.

Data hiding occurs when you do not show the user the data members. You do this by implementing a proxy class that has the actual data but the class you publish to your user only has an instance of the proxy class as a data member.

Abstraction occurs when you hide the implementation of the members. All the user sees are function prototypes.

Polymorphism occurs when you use only base class methods to support multiple classes in a hierarchy. Like a base class of Shape and derived classes of Circle, Square, Triangle. Create a derived class object, call a base class method and it is the derived method that executes. In C++ this is implemented by usng virtual functions.

Inheritance programming occurs when you use only derived class methods to support multiple classes in a hierarchy. Base class methods are accessed only by derived class methods. Base class methods represent default, or inherited, behavior.


I recommend research reading as these subjects take a little work to understand clearly.
Oct 23 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.