Top 30 Python OOPs Quiz Questions You Must Solve

Welcome to this ultimate Python OOPs quiz! Here, we have collected the most important 30 multiple-choice questions based on Python OOP concepts like classes, objects, constructor, self, cls, static methods, class methods, instance behavior, and class variable behavior.

These 30 MCQ quiz will test your knowledge from basic to advanced level as well as level up your understanding in OOPs knowledge.

Whether you’re a beginner or an experienced Python programmer, this quiz is perfect for interviews, competitive programming, and enhancing your knowledge in Python OOPs. So, are you ready to score 30/30? Let’s see, how well do you really understand OOPs concepts in Python? Let’s begin with question number 1.👇

1. Which of the following is not a core concept of Object-Oriented Programming (OOP)?
A. Encapsulation
B. Inheritance
C. Compilation
D. Polymorphism
c
Compilation is not a concept of OOP. The main principles of OOPs concepts are Encapsulation, Inheritance, Polymorphism, and Abstraction. 
2. What is the main objective of Object-Oriented Programming (OOP)?
A. Efficient memory utilization
B. Procedural abstraction
C. To make the programs run faster
D. Code reusability and modularity
d
The main objective of object-oriented programming (OOP) is to structure programs by encapsulating related data and methods into reusable and modular units called objects. This approach promotes code organization, reusability, modularity, scalability, maintainability, and abstraction.
3. What is a class in Python?
A. A built-in function.
B. A variable that holds multiple values.
C. A blueprint for creating objects.
D. None of these
c
In object-oriented programming, a class is a blueprint or template for creating objects. It defines the structure (attributes) and behavior (methods) that objects of that class will possess.
4. What is an object in Python?
A. A function inside a class
B. A module in Python
C. A built-in data type
D. An instance of a class
d
An object is an instance of a class. When you create an object of a class, it contains real data (attributes) and behaviors (methods).
5. What does the self keyword represent in a Python class?
A. It refers to the parent class.
B. It refers to the class itself.
C. It refers to the current instance of the class.
D. Used to define static methods.
c
The keyword “self” refers to the current instance of the class. It is used to access instance variables and methods within that class.
6. What will the following code output?
class Test:
    def __init__(self):
        print("Constructor called")
obj = Test()
A. Error
B. Constructor called
C. Nothing
D. init
b
When obj = Test() is executed, it automatically calls the constructor __init__.
7. What will be the output of this code?
class MyClass:
    x = 10
obj1 = MyClass()
obj2 = MyClass()
obj1.x = 20
print(obj2.x)
A. 10
B. 20
C. Error
D. None
a
x is a class variable. obj1.x = 20 creates an instance variable x for obj1 only. obj2.x still refers to the class variable, which is 10.
8. Which method does not require self or cls as the first argument?
A. Instance method
B. Class method
C. Static method
D. Constructor
c
A static method is declared using the @staticmethod decorator. It doesn’t take self or cls as its first argument because it is independent of instance and class.
9. Which of the following statement is not true about an instance method?
A. Instance method can access class variables.
B. Instance method can modify instance variables.
C. It use cls as the first parameter.
D. It can access other instance methods.
c
Instance methods use self as the first parameter, not cls.
10. What is the correct way to define a class method?
A. def method(cls):
B. @classmethod def method(cls):
C. @classmethod def method(self):
D. @staticmethod def method(cls):
b
A class method must have @classmethod decorator and cls as the first parameter.
11. What is a static variable in Python?
A. A variable defined inside a method.
B. A variable that cannot be changed.
C. A variable only accessible within a function.
D. A variable shared across all instances of a class.
d
Static variables (class variables) are defined within the class but outside methods and are shared across all instances of the class.
12. What will the following code print?
class A:
    def __init__(self):
        self.name = "A"
    def show(self):
        print("Name:", self.name)
obj = A()
obj.show()
A. Error
B. Name: A
C. A
D. Name
b
The constructor initializes the name attribute, and show() prints it.
13. What will be the expected output of the following Python code?
class Demo:
    count = 0
    def __init__(self):
        Demo.count += 1
print(Demo.count)
a = Demo()
b = Demo()
print(Demo.count)
A. 0, 1
B. 1, 1
C. 0, 2
D. 1, 2
c
count is a class variable. Initially, it is set at 0. Each time an object is created, the constructor increments Demo.count.
14. Which of the following best describes encapsulation in Python?
A. Wrapping data and methods into a single unit.
B. Inheriting from multiple classes.
C. Using private and public methods.
D. Reusing code.
a
Encapsulation in Python is a core principle of object-oriented programming (OOP), that wraps data and methods into a single unit.
15. What will be the output of this code?
class A:
    def __init__(self):
        self.x = 5
    def modify(self):
        self.x += 1
obj1 = A()
obj2 = A()
obj1.modify()
print(obj1.x, obj2.x)
A. 6, 6
B. 5, 6
C. 5, 5
D. 6, 5
d
Each object has its own x. obj1.modify() increments only obj1.x.
16. What will be the output of the following Python code if no error found?
class Test:
    x = 10
    def __init__(self, val):
        self.y = val
obj1 = Test(5)
obj2 = Test(15)
print(obj1.x, obj2.x, Test.x)
A. 10 10 10
B. 5 15 10
C. 10 15 5
D. 10 5 15
a
x is a static (class) variable, so it is shared across all instances of the class Test.
17. What is the expected output of the below Python program?
class MyClass:
    a = 10
    @classmethod
    def change_a(cls, value):
        cls.a = value
MyClass.change_a(30)
print(MyClass.a)
A. 10
B. 30
C. TypeError
D. NameError
b
The class method change_a() modifies the class variable a. Class methods are used to work with class-level data shared among all instances of the class.
18. What is the output of the following Python code?
class Car:
    wheels = 4  
    def __init__(self, brand):
        self.brand = brand 
car1 = Car("Toyota")
car2 = Car("BMW")
car1.wheels = 6
print(car1.wheels, car2.wheels, Car.wheels)
A. 4 4 4
B. 6 6 6
C. 6 4 6
D. 6 4 4
d
wheels is a class variable that is shared by all instances of Car by default unless shadowed by an instance variable. The line car1.wheels = 6 creates a new instance variable wheels for car1 only, and does not modify the class variable Car.wheels.
19. What happens when you forget to use self in an instance method?
A. Method still works
B. SyntaxError
C. TypeError at runtime
D. Creates a static method
c
Without self, Python doesn’t pass the object, causing a TypeError.
20. Which of the following method is used to modify class variables?
A. Instance method
B. Static method
C. Constructor (__init__)
D. Class method (@classmethod)
d
Class methods take cls as the first argument and can modify class-level attributes.
21. What is the key difference between @classmethod and @staticmethod?
A. @classmethod can modify class state; @staticmethod cannot.
B. @staticmethod takes self; @classmethod takes cls.
C. @classmethod is only for inheritance.
D. There is no difference.
a
@classmethod gets cls argument to access/modify class variables, while @staticmethod neither take cls or self argument. Therefore, @staticmethod cannot access instance (self) or class (cls) variables unless explicitly passed.
22. Which OOP concept allows a subclass to inherit features from a superclass?
A. Polymorphism
B. Abstraction
C. Inheritance
D. Encapsulation
c
Inheritance allows you to create a subclass to reuse attributes/methods from its parent class.
23.
class Test:
    def __init__(self):
        self.data = "Instance"
    @staticmethod
    def print_data():
        try:
            print(self.data)
        except Exception as e:
            print("Error:", e)
Test.print_data()
A. Instance
B. Error: ‘self’ is not defined
C. Error: data not defined
D. Error
b
Static method cannot access instance variable because it does not take self argument.
24. When should you use @property decorator in Python OOP?
A. To define a class method
B. To make an attribute read-only or add validation
C. To replace @staticmethod
D. To initialize instance variables
b
The @property decorator in Python lets you define getter/setter methods for controlled attribute access.
25. What is wrong with this code?
class Dog:
    def __init__(self, name):
        self.name = name
    @staticmethod
    def bark():
        print(f"{self.name} barks!")
dog = Dog("Buddy")
dog.bark()
A. @staticmethod cannot access self.
B. Missing @classmethod.
C. name should be a class variable.
D. No errors
a
Static methods don’t have access to self or instance variables. Fix: Remove @staticmethod or use an instance method.
26. What happens when a class variable and an instance variable have the same name?
A. Class variable gets updated.
B. Instance variable shadows the class variable.
C. Python raises an error.
D. None
b
Python first looks in the instance variable. If an instance variable of the same name exists, it hides the class variable.
27. What will be the output of the below code if no error found?
class MyClass:
    val = []
    def __init__(self, data):
        self.val.append(data)
a = MyClass(1)
b = MyClass(2)
print(a.val)
A. [1]
B. [2]
C. [1, 2]
D. TypeError
c
val is a class variable. All instances share the same list, so both additions affect the same list.
28. What will the following code print?
class A:
    def __init__(self):
        pass
    def method(self):
        print("Instance method")
    @staticmethod
    def method():
        print("Static method")
A().method()
A. Instance method
B. Static method
C. NameError
D. Nothing
b
The static method overrides the instance method due to same name. The last defined version is used.
29. What will be printed output for the below Python code?
class A:
    @classmethod
    def foo(cls):
        print("class method")
    @staticmethod
    def foo():
        print("static method")
A.foo()
A. class method
B. static method
C. Both methods are called one by one.
D. Error
b
Since both methods are named foo(), the static method overrides the class method.
30. What will the below Python code output?
class Test:
    a = 10
    def __init__(self):
        self.a = 20
    @classmethod
    def print_a(cls):
        print(cls.a)
Test().print_a()
A. 10
B. 20
C. TypeError
D. NameError
a
Class method accesses cls.a, which refers to the class variable a = 10. It doesn’t see the instance variable.

Quiz Results

0
Total Questions
0
Correct Answers
0
Incorrect Answers
0%
Score
You can do better next time!