:PRESENTED BY: SHUBHAM KANDHARKAR SHUBHAM BHAGEL NIKET KOTHARI MANJEET SINGH ALHAWAT PRANAV TOSHNIWAL.

Slides:



Advertisements
Similar presentations
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Advertisements

CSI 3125, Preliminaries, page 1 Polymorphism, Virtual function.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Polymorphism, Virtual Methods and Abstract Classes.
OOP Spring 2007 – Recitation 71 Object Oriented Programming Spring 2006 Recitation 8.
OOP Etgar 2008 – Recitation 71 Object Oriented Programming Etgar 2008 Recitation 7.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
VIRTUAL FUNCTIONS AND DYNAMIC POLYMORPHISM. *Polymorphism refers to the property by which objects belonging to different classes are able to respond to.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
1 Data Structures - CSCI 102 CS102 C++ Polymorphism Prof Tejada.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Polymorphism. Introduction ‘one name multiple forms’ Implemented using overloaded functions and operators Early binding or static binding or static linking.
Polymorphism &Virtual Functions
Polymorphism &Virtual Functions 1. Polymorphism in C++ 2 types ▫Compile time polymorphism  Uses static or early binding  Example: Function and operator.
Object-Oriented Programming: Polymorphism 1. OBJECTIVES What polymorphism is, how it makes programming more convenient, and how it makes systems more.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
CS212: Object Oriented Analysis and Design Lecture 15: Inheritance in C++ -II.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
Polymorphism and Virtual Functions. Topics Polymorphism Virtual Functions Pure Virtual Functions Abstract Base Classes Virtual Destructors V-Tables Run.
Chapter 10 Inheritance and Polymorphism
Copyright 2006 Oxford Consulting, Ltd1 February Polymorphism Polymorphism Polymorphism is a major strength of an object centered paradigm Same.
Topic 1 11/18/2015. Submitted By: Arslan Ali : Roll No: 6703 Ali Ahmad : Roll No: 6710 Ameer Moavia : Roll No: 6734 Abdul Manam : Roll No: 6738 Agha Waqas.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
CS212: Object Oriented Analysis and Design Lecture 17: Virtual Functions.
CS212: Object Oriented Analysis and Design
Inheritance: Base and Derived Classes. Introduction In dictionary inheritance is defined as the action of inheriting; the transfer of property; to receive.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
1 More Operator Overloading Chapter Objectives You will be able to: Define and use an overloaded operator to output objects of your own classes.
Operator overloading: Overloading a unary operator is similar to overloading a binary operator except that there is one Operand to deal with. When you.
Function Overloading and References
Chapter -6 Polymorphism
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
Polymorphism, Virtual Methods and Interfaces Version 1.1.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
Learners Support Publications Constructors and Destructors.
1 Inheritance and Polymorphism Chapter Getting Started Continue the Cat Management example from previous presentation.
Polymorphism & Virtual Functions 1. Objectives 2  Polymorphism in C++  Pointers to derived classes  Important point on inheritance  Introduction to.
 Virtual Function Concepts: Abstract Classes & Pure Virtual Functions, Virtual Base classes, Friend functions, Static Functions, Assignment & copy initialization,
CPSC 252Inheritance II Page 1 Inheritance & Pointers Consider the following client code: const int MAXCLOCKS = 2; Clock* clockPtr[ MAXCLOCKS ]; clockPtr[0]
Constructors and Destructors
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Polymorphism, Virtual Methods and Abstract Classes
Polymorphism &Virtual Functions
Class A { public : Int x; A()
CS212: Object Oriented Analysis and Design
Polymorphism & Virtual Functions
Polymorphism Lec
Virtual Functions Department of CSE, BUET Chapter 10.
Anatomy of Polymorphism
Polymorphism Polymorphism
Constructors and Destructors
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
Sampath Kumar S Assistant Professor, SECE
Pointers Dr. Bhargavi Goswami Department of Computer Science
Virtual Functions Polymorphism is supported by C++ both at compile time and at run time. Compile-time polymorphism is achieved by overloading functions.
POLYMORPHISM ( in C++) POLYMORPHISM ( in C++). Presentation Outline Polymorphism Definition Types – Compile time and Run time polymorphism Function overloading.
Inheritance: Polymorphism and Virtual Functions
VIRTUAL FUNCTIONS RITIKA SHARMA.
Inheriting Multiple Base Classes
Anatomy of Polymorphism
Eighth step for Learning C++ Programming
COP 3330 Object-oriented Programming in C++
C++ Polymorphism Reference and pointer implicit type casting
C++ Object Oriented 1.
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Computer Science II for Majors
Presentation transcript:

:PRESENTED BY: SHUBHAM KANDHARKAR SHUBHAM BHAGEL NIKET KOTHARI MANJEET SINGH ALHAWAT PRANAV TOSHNIWAL

POLYMORPHISM COMPILE TIME POLYMORPHISM RUN TIME POLYMORPHISM FUNCTION OVERLOADING OPERATOR OVERLOADING VIRTUAL FUNCTIONS

When we use the same function name in both base and derived classes, the function in base class is declared as virtual using the keyword virtual preceding its normal declaration. When a function is made virtual, c ++ determines which function to use at run time based on the type of objects pointed to by the base pointer, rather than the type of the pointer. Thus making the base pointer to point to different objects, we can execute different versions of the virtual function.

// c + + program to demonstrate the concept of virtual function #include Class base { Public: Void display( ) { cout <<“\n Display Base” ; } Virtual void show ( ) { cout<<“\n Show 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 \n” ; bptr=&B; bptr -> display( ); //calls base version bptr -> show( ); //calls base version Cout<<“\n\n bptr points to derived \n” ; bptr = &D; bptr ->display( ) ; //calls base version bptr ->show( ); //calls derived version return0;

Output : bptr points to base Display base Show base bptr points to derived Display base Show derived

Advantages and dissadvantages  Advantages 1. We can override functionality in (Derived or Child) class.  Disadvantages 1. The function call takes slightly longer due to the virtual mechanism, and it also makes it more difficult for the compiler to optimize because it doesn't know exactly which function is going to be called at compile time

2. Using base class object we can access, derived class functions. 2. In a complex system, virtual functions can make it a little more difficult to figure out where a function is being called from. Or, to figure out why a function isn't being called if someone overrode it with a new virtual function.

When we have not defined any object of class media and therefore the function show( ) in the base class has been defined empty.such functions are called as do nothing functions. A ‘do-nothing’ function may be defined as follows: virtual void show( ) = 0; such do-nothing functions are called as virtual functions. A pure virtual function is a function declared in a base class that has no definitions relative to the base class.

Remember that a class containing pure virtual functions cannot be used to declare any objects of its own.

//c ++ program to demonstrate the use of pure virtual function #include Class a { Public: virtual void example ( ) = 0; //denotes pure virtual function definition }; Class b : public a { Public:

Void example( ) { Cout<<“DIEMS”<<endl; } Class c : public a { Public: void example ( ) { cout<<“DIEMS AURANGABAD”<<endl; } };

void main() { Exforsys* arra[2]; b e1; c e2; arra[0] = &e1; arra[1] = &e2; arra[0] -> example(); arra[1] -> example(); }

Output: DIEMS DIEMS AURANGABAD

THANK YOU