Paper Details  
 
   

Has Bibliography
3 Pages
691 Words

 
   
   
    Filter Topics  
 
     
   
 

Polymorphism in C

The problem is that we need to compress our programs while still having them function correctly and process items differently depending on type or class. The solution is polymorphism. Polymorphism in object oriented programming is the programming language’s ability to process items differently depending on their data type or class. In other words, it is the ability to redefine methods for derived classes. The true rule for C++ polymorphism is that when one class, named A is derived from or “inherits” another class, named B, A can do anything that B can do, thus it can store pointers to A in variables declared as B. Here are examples for and the definitions of the three types of polymorphism. If you were to have a base class named shape, polymorphism lets the programmer define different and separate circumference methods for any number of derived classes, such as circles, rectangles, and triangles. No matter what the shape of the object is, the circumference method will always return correct. This is an example of one of three types of polymorphism. This specific type is known as parameterized polymorphism, or parametric polymorphism.Another type of polymorphism is called overloading. Overloading is a form of polymorphism that allows an object to have different meanings depending on context. It is most often used to reference operators that can behave differently because of the data type class or operands. This is best illustrated using X+Y. X+Y can mean different things depending on wheather x and y are simple intergers or complex data structures. Here is a clearer example:4 + 5 *-- integer addition3.14 + 2.0 *-- floating point additions1 + "bar" *-- string concatenation!The final form of polymorphism is called pure polymorphism. This form of polymorphism is a selection of a function at run time based on the class type and its position in an inheritance hierarchy. Now here is an example of polym...

Page 1 of 3 Next >

    More on Polymorphism in C...

    Loading...
 
Copyright © 1999 - 2024 CollegeTermPapers.com. All Rights Reserved. DMCA