Oops
Oops
Programming Using
Index
1. Introduction to Object Oriented Programming in Python
2. Difference between object and procedural oriented
programming
3. What are Classes and Objects?
4. Object-Oriented Programming methodologies:
1
• Inheritance
• Polymorphism
• Encapsulation
• Abstraction
3
2. Difference between Object-Oriented and
Procedural Oriented Programming
Procedural-Oriented Programming
Object-Oriented Programming (OOP)
(Pop)
Example:
5
Creating an Object and Class in python:
Example:
6
class employee():
def __ init__( self,name,age,id,salary): //creating a function
self.name = name // self is an instance of a class
self.age = age
self.salary = salary
self.id = id
4. Object-Oriented Programming
methodologies:
7
❑ Inheritance
❑ Polymorphism
❑ Encapsulation
❑ Abstraction
Inheritance:
Polymorphism:
This code demonstrates the concept of Python oops inheritance
and method overriding in Python classes. It shows how
subclasses can override methods defined in their parent class
to provide specific behavior while still inheriting other methods
from the parent class.
16
Polymorphism is of two types:
❑ Compile-time Polymorphism
❑ Run-time Polymorphism
17
Compile-time Polymorphism:
18
Run-time Polymorphism:
A run-time Polymorphism is also, called as dynamic
polymorphism where it gets resolved into the run time. One
common example of Run-time polymorphism is “method
overriding”.
Encapsulation:
19
In Python object oriented programming, Encapsulation is one
of the fundamental concepts in object-oriented programming
(OOP). It describes the idea of wrapping data and the
methods that work on data within one unit. This puts
restrictions on accessing variables and methods directly and
can prevent the accidental modification of data. To prevent
accidental change, an object’s variable can only be changed
by an object’s method. Those types of variables are known as
private variables.
A class is an example of encapsulation as it encapsulates all
the data that is member functions, variables, etc.
20
Abstraction:
It hides unnecessary code details from the user. Also, when
we do not want to give out sensitive parts of our code
implementation and this is where data abstraction came.
21