Polymorphism in c++ ppt | Polymorphism in c++ with example ppt

Views:
 
Category: Education
     
 

Presentation Description

Learn about What is polymorphism in c++ , Polymorphism in c++ with example , Types of polymorphism in c++ and for more visit www.cprogrammings.com

Comments

Presentation Transcript

PowerPoint Presentation: 

Polymorphism in C++

PowerPoint Presentation: 

What is Inheritance Polymorphism is the ability to use an operator or function in different ways. Polymorphism gives different meanings or functions to the operators or functions.

PowerPoint Presentation: 

Poly, referring to many, signifies the many uses of these operators and functions. A single function usage or an operator functioning in many ways can be called polymorphism. Polymorphism refers to codes, operations or objects that behave differently in different contexts.

PowerPoint Presentation: 

#include <iostream> using namespace std; class CPolygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; } }; class CRectangle: public CPolygon { public: int area () { return (width * height); } }; Example of Inheritance

PowerPoint Presentation: 

class CTriangle: public CPolygon { public: int area () { return (width * height / 2); } };

PowerPoint Presentation: 

Int main () { CRectangle rect; CTriangle trgl; CPolygon * ppoly1 = &rect; CPolygon * ppoly2 = &trgl; ppoly1->set_values (4,5); ppoly2->set_values (4,5); cout << rect.area() << endl; cout << trgl.area() << endl; return 0; }

PowerPoint Presentation: 

Get more programming tutorial www.cprogrammings.com