• Tutorials
  • Courses
  • Tracks

Python OOPs quiz

Last Updated :
Discuss
Comments

Question 1

In Python, what is a class?

  • A function

  • A module

  • A code block

  • A blueprint for creating objects

Question 2

What is the role of the __metaclass__ attribute in Python?

  • To define class properties

  • To specify the superclass of a class

  • To indicate the metaclass of a class

  • 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?

  • To define class properties

  • To restrict access to certain components of an object

  • To create read-only properties.

  • To initialize instance variables

Question 4

What is dynamic polymorphism in OOP?

  • The ability to create objects at runtime

  • The ability to change the type of a variable dynamically

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

  • The ability to define methods with different names in a class

Question 5

What is the primary purpose of multiple inheritance in OOP?

  • To create complex class hierarchies

  • To combine attributes from multiple classes

  • To allow a class to inherit from more than one superclass

  • To override methods in multiple classes

Question 6

How does encapsulation contribute to data protection in OOP?

  • By exposing all class attributes publicly

  • By allowing direct access to private attributes

  • By restricting access to certain components of an object

  • By promoting global access to class members

Question 7

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

  • Initializing class variables

  • Declaring instance variables

  • Defining methods for the class

  • Creating a new class

Question 8

How can you implement encapsulation in Python?

  • By using private variables and methods

  • By defining multiple methods with the same name in a class

  • By creating a new instance of a class

  • By using the @property decorator

Question 9

What is the purpose of the __str__ method in Python?

  • To convert an object to a string representation

  • To define abstract methods in a class

  • To perform cleanup activities when an object is no longer needed

  • To initialize instance variables

Question 10

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

  • By using the abstract keyword

  • By defining methods with the @abstractmethod decorator

  • By using the abstract attribute in the class definition

  • By creating a class with no concrete methods

There are 27 questions to complete.

Take a part in the ongoing discussion