EE172_Lecture_5 inheritance and polymorphism
EE172_Lecture_5 inheritance and polymorphism
Lecture 5:
Object Oriented Programming (OOP)
1
What is OOP
Pillars of OOP
Inheritance
Polymorphism
2
Inheritance
3
Animal::legs
cannot be
inherited!!
7
Inheritance (Access Modes)
8
10
Single Inheritance
11
Base Class
Derived Class
Single Inheritance
12
Multilevel Inheritance
13
Derived Class B
Derived Class C
Multilevel Inheritance
14
Multiple Inheritance
15
Derived Class C
Multiple Inheritance
Derived class
Bulldog inherits from
Animal and Dog
16
Hierarchical Inheritance
17
Base Class
18
Hybrid Inheritance
19
Multiple
inheritance
D-3
What is OOP
Pillars of OOP
Inheritance
Polymorphism
20
Polymorphism
21
Function overloading
Operator overloading
Function overriding
Virtual functions
Function Overloading
23
In C++, we can use two functions having the same name if they have
different parameters (either types or number of arguments).
Depending upon the number/type of arguments, the same function
can perform the task in different ways
Function Overloading
Sum of three
integers
Sum of double
numbers
24
Operator Overloading
25
=9
= ABCDEF
Operator Overloading
Adding two
numbers
26
Function Overriding
27
In C++ inheritance, we can have the same function in the base class
as well as its derived classes
Function overriding occurs when a derived class has the same
definition of a functions from the base class.
Therefore the base function is said to be overridden.
Base class
sum(int a, int b)
Derived class
sum (int a, int b)
Function Overriding
Derived class
with the same
function
28
29