Unit 4
Unit 4
● Functional
● Procedural
● Object oriented
Object oriented programming
Python Classes and Objects
●
●
●
Object of Python Class
● The self parameter is a reference to the current instance of the class and
is used to access variables that belong to the class.
● It must be the first parameter of any function in the class (methods) so
that they can access the attributes and other methods of the class.
● The name self is a convention and not a keyword. You can use any name,
but self is the widely accepted convention.
__init__ Method
● The super keyword in Python is used to call a method from the parent
class.
● It is commonly used in the context of inheritance, allowing the child class
to access methods and constructors of the parent class without
explicitly naming the parent class.
Multiple Inheritance
When a class is derived from more than one base class it is called multiple Inheritance.
The derived class inherits all the features of the base class.
Multiple Inheritance
Multiple Inheritance
Multiple Inheritance
Multilevel Inheritance
Derived classes: These inherit from the base class and add specific traits
Multilevel Inheritance
Multilevel Inheritance
Output
Hierarchical Inheritance
● The members of a class that are declared protected are only accessible to a
class derived from it.
● Data members of a class are declared protected by adding a single underscore
‘_’ symbol before the data member of that class.
Protected Access Modifier:
Private Access Modifier:
●
Private Access Modifier:
Encapsulation
● Encapsulation is the bundling of data (attributes) and methods (functions) that operate
on the data into a single unit or class.
● It also restricts direct access to some of an object's components, which is a means of
preventing accidental interference and misuse of the data.
Encapsulation
●
Encapsulation
Encapsulation
Polymorphism
Polymorphism
Polymorphism