Python OOP quiz

Last Updated :
Discuss
Comments

Question 1

What is a class in Object Oriented Programming?

  • A

    A function

  • B

    A module

  • C

    A code block

  • D

    A blueprint for creating objects

Question 2

What is the role of the __metaclass__ attribute in Python?

  • A

    To define class properties

  • B

    To specify the superclass of a class

  • C

    To indicate the metaclass of a class

  • D

    To restrict the creation of new attributes in an instance

Question 3

In the context of encapsulation, what is the purpose of access modifiers in Python?

  • A

    To define class properties

  • B

    To restrict access to certain components of an object

  • C

    To create read-only properties.

  • D

    To initialize instance variables

Question 4

What is dynamic polymorphism in OOP?

  • A

    The ability to create objects at runtime

  • B

    The ability to change the type of a variable dynamically

  • C

    The ability to provide a single interface for different types at runtime

  • D

    The ability to define methods with different names in a class

Question 5

What is the primary purpose of multiple inheritance in OOP?

  • A

    To create complex class hierarchies

  • B

    To combine attributes from multiple classes

  • C

    To allow a class to inherit from more than one superclass

  • D

    To override methods in multiple classes

Question 6

How does encapsulation contribute to data protection in OOP?

  • A

    By exposing all class attributes publicly

  • B

    By allowing direct access to private attributes

  • C

    By restricting access to certain components of an object

  • D

    By promoting global access to class members

Question 7

What is the purpose of the __init__ method in a Python class?

  • A

    Initializing class variables

  • B

    Declaring instance variables

  • C

    Defining methods for the class

  • D

    Creating a new class

Question 8

How can you implement encapsulation in Python?

  • A

    By using private variables and methods

  • B

    By defining multiple methods with the same name in a class

  • C

    By creating a new instance of a class

  • D

    By using the @property decorator

Question 9

What is the purpose of the __str__ method in Python?

  • A

    To convert an object to a string representation

  • B

    To define abstract methods in a class

  • C

    To perform cleanup activities when an object is no longer needed

  • D

    To initialize instance variables

Question 10

How can you create an abstract class in Python using the abc module?

  • A

    By using the abstract keyword

  • B

    By defining methods with the @abstractmethod decorator

  • C

    By using the abstract attribute in the class definition

  • D

    By creating a class with no concrete methods

There are 27 questions to complete.

Take a part in the ongoing discussion