0% found this document useful (0 votes)
14 views21 pages

Oops

td

Uploaded by

sureshjallella9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views21 pages

Oops

td

Uploaded by

sureshjallella9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Object Oriented

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

1. Introduction to Object Oriented

Programming Python in Python


Object Oriented Programming is a way of
computer programming using the idea of
“objects” to represents data and methods. It is
also, an approach used for creating neat and
reusable code instead of a redundant one.

3
2. Difference between Object-Oriented and
Procedural Oriented Programming
Procedural-Oriented Programming
Object-Oriented Programming (OOP)
(Pop)

It is a bottom-up approach It is a top-down approach

Program is divided into objects Program is divided into functions

Makes use of Access modifiers ‘public’,


Doesn’t use Access modifiers
private’, protected’

It is more secure It is less secure

It supports inheritance It does not support inheritance


3. What are Classes and Objects?

A class is a collection of objects or you can say it is a


blueprint of objects defining the common attributes and
behavior. Now the question arises, how do you do that?

Class is defined under a “Class” Keyword.

Example:

class class1(): // class 1 is the name of the class

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

emp1 = employee("harshit",22,1000,1234) //creating objects


emp2 = employee("arjun",23,2000,2234)
print(emp1.__dict__)//Prints dictionary

4. Object-Oriented Programming
methodologies:
7
❑ Inheritance
❑ Polymorphism
❑ Encapsulation
❑ Abstraction
Inheritance:

In Python object oriented Programming, Inheritance is the


capability of one class to derive or inherit the properties from
another class. The class that derives properties is called the
derived class or child class and the class from which the
properties are being derived is called the base class or parent
class. The benefits of inheritance are:

 It represents real-world relationships well.

 It provides the reusability of a code. We don’t have to


write the same code again and again. Also, it allows us to
add more features to a class without modifying it.

 It is transitive in nature, which means that if class B


inherits from another class A, then all the subclasses of B
would automatically inherit from class A.
9
11
Single Inheritance:

Single level inheritance enables a derived class to inherit


characteristics from a single parent class.
Multilevel Inheritance:
Multi-level inheritance enables a derived class to inherit properties from an
immediate parent class which in turn inherits properties from his parent
class.

Hierarchical level inheritance enables more than one derived


class to inherit properties from a parent class.
Multiple Inheritance:

Multiple level inheritance enables one derived class to inherit


properties from more than one base class.

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:

A compile-time polymorphism also called as static


polymorphism which gets resolved during the compilation
time of the program. One common example is “method
overloading”

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.

Data Abstraction in Python can be achieved by creating


abstract classes.

21

You might also like