You are on page 1of 17

ASSIGNMENT: THE OBJECT

ORIENTED PROGRAMING
(OOP) CONCEPT
(P O LY M O R P H I S M )
Mr. Farhad Khan
Tue 01 Feb, 2022
Polymorphism
• Background: The word Polymorphism is
derived from two Greek words i.e. “Poly” and
“Morphs”
• Poly means MANY while Morphs means
FORMS
• So Polymorphism is the ability of a
programing language to present the same
interface for several different underlying data
types
Polymorphism (Daily Life Example)
• In OOP the Polymorphism means single
object having many forms
• Same as a single Person in daily life, may be a
Father, a Husband, an Employee and a
Driver at the same time
• Same person posses different behavior in
different situations
• This is called polymorphism
Types of Polymorphism

Polymorphism

Compile Time Runtime


Polymorphism Polymorphism

Method Operator Method


overloading overloading Overriding
Compile Time Polymorphism (CTP)
• Compile Time Polymorphism means the
processing version is known to control before
converting source code to machine code
• It is also known as Static or Early Binding
• It is achieved by:
1. Method Overloading
2. Operator Overloading
Run Time Polymorphism (RTP)
• Run Time Polymorphism means the
processing version is known to control during
the execution of machine code
• It is achieved by:
1. Method Overriding
Method Overloading
• Two or more methods with same name but
different signatures
• Different signatures means:
1. Difference in numbers of parameters
2. Difference in data types of parameters
• This feature of CTP is used to increase
readability of the program
C# Example (Method Overloading)
(Different Number of Parameters)
Conti. . .
Conti. . .
(Different Data Types of Parameters)
Conti. . .
Operator Overloading

• Same Operator or Symbol to be used for


multiple Operations
• More then one implementation of an
Operator
• Example of the “+” Operator i.e. Overloaded
• To be used for Addition of Integer data types
• To be use for concatenation of string data
types
Method Overriding
• Method Overriding is used to achieve RTP
• Way of defining method of a Parent Class
(Base/Super Class) inside its Child Class
(Sub/Derived Class) to provide a specific
implementation
• Method Overriding, is achieved by defining a
method with the key word Virtual (Virtual Method)
in Super Class
• The same Virtual Method will be re-defined with
the key word Override (Override Method) in Sub
Class
Conti. . .
C# Example (Method Overriding)
Conti. . .
ANY QUESTIONS?
THANK YOU EVERYONE

You might also like