Top Banner
MEWAR INSTITUTE OF MANAGEMENT SUBMITTED TO: ASHEESH PANDEY SIR SUBMITTED BY: SHEETAL SINGH BCA 2 ND YEAR 1590409046
15

polymorphism ppt

Jan 06, 2017

Download

Documents

sheetal singh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: polymorphism ppt

MEWAR INSTITUTE OF MANAGEMENT

SUBMITTED TO: ASHEESH PANDEY SIRSUBMITTED BY: SHEETAL SINGH

BCA 2ND YEAR 1590409046

Page 2: polymorphism ppt

POLYMORPHISM &

ITS TYPE

Page 3: polymorphism ppt

POLYMORPHISM • The process of representing one form in multiple forms is known

as polymorphism• Polymorphism is derived from 2 Greek words: poly and morphs.

The word "poly" means many and morphs means forms. So polymorphism means many forms

Real life example

Page 4: polymorphism ppt

HOW CAN WE ACCESS THE MEMBER OF CLASS

The member of class can be access through pointer to the classGeneral syntax P->member class;P is pointer of object-> is member access operatorMember class it is the member of the object

Page 5: polymorphism ppt

POLYMORPHISM

COMPILE TIME

POLYMORPHISM

RUN TIME POLYMORPH

ISM

FUNCTION OVERLODI

NG

OPERATOR OVERLODI

NGVIRTUAL

FUNCTION

Page 6: polymorphism ppt

COMPILE TIME POLYMORPHISM

• It is also known as static binding, early binding and overloading as well

• It provides fast execution because known early at compile time compile time

• Polymorphism is less flexible as all things execute at compile time.

• It is achieved by function overloading and operator overloading

Page 7: polymorphism ppt

COMPILE TIME POLYMORPHISM

FUNCTION OVERLOADING

• Overloading refers to the use of the same thing for different purpose• Function overloading is a

logical method of calling several function with different datatype and argument but name of function is the same

OPERATOR OVERLOADING

• In C++ the overloading principle applies not only to functions, but to operators too.

•  Overloaded operator is used to perform operation on user-defined data type. For example '+' operator can be overloaded to perform addition on various data types, like for integer, string(concatenation) etc.

Page 8: polymorphism ppt

RUN TIME POLYMORPHISM

• It is also known as dynamic binding, late binding and overriding as well

• It provides slow execution as compare to early binding because it is known at runtime

• Run time polymorphism is more flexible as all things execute at run time.

• It is achieved by virtual functions and pointers

Page 9: polymorphism ppt

VIRTUAL FUNCTION

It is a special type of function

It can be declared within base class and redefine by derived class

Its name will be same in every class

In derived class it will be executed through pointer of base class

It is declared by the keyword “virtual”

A redefined function is said to override the base class function

Page 10: polymorphism ppt

PROGRAM RELATED TO

VIRTUAL FUNCTION

Page 11: polymorphism ppt

#include<iostream.h>class base{

public:void display()

{cout<<“display base”;}virtual void show()

{cout<<“\nshow base”;}};

class derived : public base

{public:

void display()

{cout<<“\n display derived”;}void show()

{cout<<“\n show derived”;}

};int main()

{base b;

derived d;base*bptr;

cout<<“\n bptr points to base”;

bptr=&b;bptr->display();

Bptr->show();Cout<<“\n bptr points to

derived”;Bptr=&d;

Bptr->display();Bptr->show();

Return 0;}

Page 12: polymorphism ppt

OUTPUTbptr points to basedisplay baseshow casebptr points to deriveddisplay baseshow derived

Page 13: polymorphism ppt

RULES OF VIRTUAL FUNCTION

• Virtual function must be member of some class• They can’t static member• Virtual function can be a friend of another class• We can’t have virtual constructor but we have virtual destructor• Virtual function is define in the base class it is not necessary to redefine in

the derived class

Page 14: polymorphism ppt

PURE VIRTUAL FUNCTION

• Pure virtual function give small definition to the abstract class . we need at least one pure virtual function to create abstract class• Pure virtual function must be define outside the function if it will

define inside the function then compiler show error

Page 15: polymorphism ppt