abstraction polymorphism nd encpsulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AliRauf
    New Member
    • Oct 2015
    • 1

    abstraction polymorphism nd encpsulation

    please tell me about abstraction polymorphism and encapsulation and with simple code example and solution
    thanks
  • jaseel97
    New Member
    • Feb 2015
    • 16

    #2
    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(usual ly 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.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      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.
      Last edited by weaknessforcats; Oct 23 '15, 04:01 PM. Reason: typo

      Comment

      Working...