MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
1. Principles of OOP with Examples & OOP Concepts in Python
Definition of OOP
Object Oriented Programming (OOP) is a programming approach
in which programs are organized around objects that represent
real-world entities. Each object contains data (attributes) and
methods (functions).
Advantages of OOP
Code reusability
Data security
Modularity
Easy maintenance
Four Main Principles of OOP
1. Encapsulation
Wrapping data and methods into a single unit (class).
class Student:
def __init__(self, name, marks):
[Link] = name
[Link] = marks
def display(self):
print([Link], [Link])
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
s = Student("Ajitha", 85)
[Link]()
✔ Data + methods are bound together.
2. Abstraction
Hiding internal details and showing only essential features.
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Rectangle(Shape):
def area(self):
return 10 * 5
r = Rectangle()
print([Link]())
✔ Only required functionality is visible.
3. Inheritance
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
One class acquires the properties of another class.
class Parent:
def show(self):
print("This is parent class")
class Child(Parent):
pass
c = Child()
[Link]()
✔ Code reusability is achieved.
4. Polymorphism
Same method name used for different implementations.
class Dog:
def sound(self):
print("Bark")
class Cat:
def sound(self):
print("Meow")
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
for obj in (Dog(), Cat()):
[Link]()
✔ Different behavior for the same method.
2. Class Attributes, Instance Attributes & Method Invocation
Class Attributes
Variables shared by all objects.
Instance Attributes
Variables specific to each object.
class Student:
college = "SREE DATTHA" # Class attribute
def __init__(self, name):
[Link] = name # Instance attribute
s1 = Student("Ajitha")
s2 = Student("Ravi")
print([Link], [Link])
print([Link], [Link])
Method Invocation
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
Calling methods using object or class.
[Link]() # Object invocation
[Link](s1) # Class invocation
3. Inheritance and Its Types
Definition
Inheritance allows one class to use the properties of another class.
Types of Inheritance in Python
1. Single Inheritance
class A:
def show(self):
print("Class A")
class B(A):
pass
b = B()
[Link]()
2. Multiple Inheritance
class A:
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
def showA(self):
print("A")
class B:
def showB(self):
print("B")
class C(A, B):
pass
c = C()
[Link]()
[Link]()
3. Multilevel Inheritance
class A:
pass
class B(A):
pass
class C(B):
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
pass
4. Hierarchical Inheritance
class A:
pass
class B(A):
pass
class C(A):
pass
5. Hybrid Inheritance
Combination of more than one type.
4. Composition and Component with Example
Composition
One object contains another object (HAS-A relationship).
class Engine:
def start(self):
print("Engine started")
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
class Car:
def __init__(self):
[Link] = Engine() # Composition
def drive(self):
[Link]()
print("Car is running")
c = Car()
[Link]()
✔ Car HAS an Engine.
Component
Independent object that can exist separately.
Example: A teacher object used in multiple classes independently.
5. Special Methods for Operator Overloading
Special methods are also called magic methods and start and end with
__.
Operat Metho
or d
+ add
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
Operat Metho
or d
- sub
* mul
== Eq
Example: Operator Overloading with +
class Number:
def __init__(self, x):
self.x = x
def __add__(self, other):
return self.x + other.x
n1 = Number(10)
n2 = Number(20)
print(n1 + n2)
✔ + operator is overloaded.
6. Privacy in Python
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
Python does not have strict private variables but supports naming
conventions.
Synta
Type
x
Public name
Protecte
_name
d
__nam
Private
e
Example
class Bank:
def __init__(self):
[Link] = "Ajitha"
self._account = 12345
self.__balance = 5000
b = Bank()
print([Link]) # Public
print(b._account) # Protected
# print(b.__balance) # Error
print(b._Bank__balance) # Name Mangling
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
7. Difference Between Types, Classes, and Instances
Feature Type Class Instance
Definitio Data
Blueprint Object
n type
Example int, str Student s1
User- Created at
Memory Built-in
defined runtime
Example
class Student:
pass
s1 = Student()
print(type(10)) # int type
print(type(Student))# class type
print(type(s1)) # instance type
8. Delegation and Wrapping with Example
Delegation
One object passes work to another object.
class Printer:
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
def print_doc(self):
print("Printing document")
class Computer:
def __init__(self):
[Link] = Printer()
def print_file(self):
[Link].print_doc() # Delegation
c = Computer()
c.print_file()
✔ Computer delegates printing to Printer.
Wrapping
Adding extra features to an existing class without modifying it.
class Message:
def send(self):
print("Message sent")
class SecureMessage:
def __init__(self, msg):
MODULE-1
1. Explain the principles of OOP with examples and Explain Object Oriented Programming
concepts in detail with Python programs.
2. Discuss class attributes, instance attributes and method invocation.
3. Explain inheritance and its types with examples.
4. Discuss composition and component with example.
5. Explain special methods used for operator overloading.
6. Explain privacy in Python.
7. Difference between Types, Classes and Instances.
8. Explain delegation and wrapping with example.
[Link] = msg
def send(self):
print("Encrypting...")
[Link]()
m = Message()
s = SecureMessage(m)
[Link]()
✔ SecureMessage wraps Message.