0% found this document useful (0 votes)
17 views

8.Oops

The document provides an overview of Object-Oriented Programming (OOP) concepts including classes, objects, inheritance, encapsulation, polymorphism, and abstraction. It explains various types of inheritance such as single, multi-level, multiple, hierarchical, and hybrid inheritance, along with constructors and destructors in Python. Key features like method overloading and overriding, as well as the significance of encapsulation and abstraction, are also discussed.

Uploaded by

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

8.Oops

The document provides an overview of Object-Oriented Programming (OOP) concepts including classes, objects, inheritance, encapsulation, polymorphism, and abstraction. It explains various types of inheritance such as single, multi-level, multiple, hierarchical, and hybrid inheritance, along with constructors and destructors in Python. Key features like method overloading and overriding, as well as the significance of encapsulation and abstraction, are also discussed.

Uploaded by

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

OOPS

PROCEDURAL vs
OOPS
OBJECT ORIENTED
PROGRAMMING
 Class
 Object
 Method
 Inheritance
 Polymorphism
 Data Abstraction
 Encapsulation
OBJECT
 The object is an entity that has state and
behavior.
 It may be any real-world object like the
mouse, keyboard, chair, table, pen, etc.
 Everything in Python is an object, and
almost everything has attributes and
methods.
OBJECT - EXAMPLE
When we define a class, it needs to create an
object to allocate memory.
CLASS

 The class can be defined as a collection of


objects.
 It is a logical entity that has some specific
attributes and methods.
CLASS - EXAMPLE
class A
Data members: // to show object state.

Member functions : // to show


object functionality

if you change the values in data members ,


it will also affect the member functions
INHERITANCE

 By using inheritance, we can create a


class which uses all the properties and
behavior of another class.
 The new class is known as a derived class
or child class, and the one whose
properties are acquired is known as a base
class or parent class.
 It provides the re-usability of the code.
SINGLE INHERITANCE
It enables a derived class to
inherit properties from a single parent
class, thus enabling code reusability and
the addition of new features to existing
code.
SINGLE INHERITANCE -
EXAMPLE
SINGLE INHERITANCE -
EXAMPLE : OUTPUT
MULTI-LEVEL INHERITANCE

 In multilevel inheritance, features of the


base class and the derived class are
further inherited into the new derived
class.
 This is similar to a relationship
representing a child and grandfather.
MULTI-LEVEL INHERITANCE -
EXAMPLE
MULTIPLE INHERITANCE
 When a class can be derived from more
than one base class this type of
inheritance is called multiple inheritance.

 In multiple inheritance, all the features


of the base classes are inherited into the
derived class.
MULTIPLE INHERITANCE -
EXAMPLE
MULTIPLE INHERITANCE -
EXAMPLE : OUTPUT
HIERARCHICAL INHERITANCE
When more than one derived classes are
created from a single base this type of
inheritance is called hierarchical inheritance.
HIERARCHICAL INHERITANCE -
EXAMPLE
HIERARCHICAL INHERITANCE -
EXAMPLE : OUTPUT
HYBRID INHERITANCE

Inheritance consisting of multiple


types of inheritance
HYBRID INHERITANCE -
EXAMPLE
HYBRID INHERITANCE -
EXAMPLE : OUTPUT
ENCAPSULATION
 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.
Encapsulation
POLYMORPHISM

 Polymorphism contains two words


"poly" and "morphs".
 Poly means many, and morph means
shape.
 By polymorphism, we understand that
one task can be performed in different
ways. .
FUNCTION OVERLOADING

SAME FUNCTION NAME BUT


DIFFERENT ARGUMENTS
FUNCTION OVERRIDING
SAME FUNCTION NAME AND
SAME ARGUMENTS.
METHOD OVERLOADING vs
METHOD OVERRIDING
ABSTRACTION
 Data abstraction and encapsulation both
are often used as synonyms.
 Abstraction is used to hide internal details
and show only functionalities.
 Inner process or back process hiding.
 Python provides the abc module to use the
abstraction in the Python program.
ABSTRACT EXAMPLE
ABSTRACT EXAMPLE - OUTPUT
CONSTRUCTOR
 Constructors are generally used for
instantiating an object.
 The task of constructors is to
initialize(assign values) to the data
members of the class when an object of
the class is created.
 In Python the __init__() method is called
the constructor and is always called when
an object is created.
 The function call automatically when the
object is initialized.
TYPES OF CONSTRUCTOR
Default constructor:

 The default constructor is a simple


constructor which doesn’t accept any
arguments.
 Its definition has only one argument which
is a reference to the instance being
constructed.
CONSTRUCTOR - EXAMPLE
TYPES OF CONSTRUCTOR
Parameterized constructor:

 The constructor with parameters is known


as parameterized constructor.
 The parameterized constructor takes its
first argument as a reference to the
instance being constructed known as self
and the rest of the arguments are
provided by the programmer.
CONSTRUCTOR - EXAMPLE
DESTRUCTORS
 Destructors are called when an object
gets destroyed.
 In Python, destructors are not needed as
much needed in C++ because Python has
a garbage collector that handles memory
management automatically.
 The __del__() method is a known as a
destructor method in Python.
 The function call automatically when the
object is destroyed
DESTRUCTORS - EXAMPLE
DESTRUCTORS - OUTPUT

You might also like