Python Oop Part1
Python Oop Part1
• Functional programming
• Procedure oriented programming
• Object oriented programming
Object Oriented Programming
• Models real world entities as software objects
• Creating Reusable code
Human
Walk Eat Sleep Behaviour/Methods
Classes and Objects
• Class is a Blueprint
• Objects are copy of the class which are real
Object 1:
Attribute: Ram, 25
Behaviour: can Speak French, can able to sing
Types of Variables
• Class/Static Variable --- Class Level
• Instance Variable --- Object Level
• Local Variable --- Method level
Sample Interview Question
Choose the correct option with respect to the
type and number of variables.
• A. The class Person has 3 instance variables, 2
local variables and 1 static variable
• B. The class Person has 3 instance variables, 1
local variables and 1 static variable
• C. The class Person has 2 instance variables, 3
local variables and 1 static variable
• D. The class Person has 4 instance variables, 2
local variables and no static variable
Inheritance
• Class that inherits all the methods and properties from another class
• Parent Child Relationship
• Parent Class/Base Class
• Child Class/Derived Class
• Code Reusability
Types of Inheritance
• Single Inheritance
-- a child class inherits only a single parent class.
• Multiple Inheritance
-- a child class inherits from more than one parent class.
• Multilevel Inheritance
-- a child class becomes a parent class for another child class.
• Hierarchical Inheritance
-- involves multiple inheritance from the same base or parent class.
Sample Interview Question
What changes should be done in the
given code so as to get the output as
201?
A. Make the instance variable of Base
class public
B. Add a constructor with statements
super().__init__() in Child class
C. Add statement super().__init__() in
the constructor of GrandChild class
D. Add a constructor in Child class
and initialize num to 201