Full OOPs Python Assessment Guide
Full OOPs Python Assessment Guide
1. Introduction to OOP
It helps structure a program into simple, reusable pieces of code blueprints (usually called classes),
A class is a user-defined blueprint or prototype from which objects are created. Objects are
instances of classes.
class Dog:
self.name = name
def bark(self):
d = Dog("Buddy")
3. Encapsulation
Encapsulation is the mechanism of hiding the internal data of an object and restricting access to it. It
class Account:
def __init__(self):
self.__balance = 0
self.__balance += amount
def get_balance(self):
return self.__balance
4. Inheritance
Inheritance is a mechanism where one class derives properties and behavior (methods) from
another class.
class Animal:
def speak(self):
class Dog(Animal):
def speak(self):
d = Dog()
5. Polymorphism
Polymorphism allows us to use a unified interface for multiple forms (data types).
class Bird:
def fly(self):
class Penguin(Bird):
def fly(self):
OOPs Concepts with Python - Assessment Preparation
def flying_test(bird):
bird.fly()
6. Abstraction
Abstraction means hiding the complexity and only showing the essential features. In Python, it can
class Vehicle(ABC):
@abstractmethod
def start(self):
pass
class Car(Vehicle):
def start(self):
print("Car started")
c = Car()
Constructors are used for initializing objects. Destructors are called when an object is deleted or
class Demo:
def __init__(self):
print("Constructor called")
def __del__(self):
print("Destructor called")
obj = Demo()
Class methods are bound to the class, not the instance. Static methods do not depend on class or
instance state.
class MyClass:
count = 0
@classmethod
def increment(cls):
cls.count += 1
@staticmethod
def greet():
print("Hello!")
MyClass.increment()
9. Operator Overloading
Operator overloading lets us redefine the behavior of operators for user-defined classes.
OOPs Concepts with Python - Assessment Preparation
class Point:
self.x = x
self.y = y
p1 = Point(1, 2)
p2 = Point(3, 4)
p3 = p1 + p2 # Uses __add__
In this section, you'll find over 100 carefully designed multiple-choice and output-based questions.
These test your conceptual understanding and Python application in OOP. [Continued on next
pages]