VOOZH about

URL: https://www.analyticsvidhya.com/blog/2024/02/mcqs-on-python-oops-concepts/

⇱ 30+ MCQs on Python OOPs Concepts


India's Most Futuristic AI Conference Is Back – Bigger, Sharper, Bolder

  • d
  • :
  • h
  • :
  • m
  • :
  • s

30+ MCQs on Python OOPs Concepts

Ayushi Trivedi Last Updated : 06 Mar, 2024
8 min read

Welcome to the Python OOPs Concepts Python Interview Questions! Object-Oriented Programming (OOP) is a powerful paradigm in Python that allows you to create classes and objects, encapsulate data and methods, and implement inheritance, polymorphism, and abstraction. These questions will test your understanding of various OOP concepts in Python, including classes, objects, inheritance, encapsulation, and polymorphism. Each question is multiple-choice, with only one correct answer. Take your time to carefully read each question and choose the best option. Let’s dive into the world of Python OOPs concepts together!

👁 Python OOPs

30+ Python Interview Questions on Python OOPs Concepts

Q1. What is OOP?

a) Out-of-Order Processing

b) Object-Oriented Programming

c) Out-of-Place Programming

d) Optimized Object Parsing

Answer: b

Explanation: OOP stands for Object-Oriented Programming, a programming paradigm based on the concept of “objects”.

Q2. What is an object in OOP?

a) A variable

b) A block of code

c) An instance of a class

d) A built-in function

Answer: c

Explanation: In OOP, an object is an instance of a class. It encapsulates data for the class and provides methods to access and modify that data.

Q3. Which of the following is NOT a basic principle of OOP?

a) Encapsulation

b) Inheritance

c) Polymorphism

d) Concatenation

Answer: d

Explanation: Concatenation is not a basic principle of OOP. Encapsulation, inheritance, and polymorphism are core principles.

Q4. What is inheritance in OOP?

a) The ability to create new classes from existing ones

b) The ability to access private members of a class

c) The ability to create objects

d) The ability to override methods

Answer: a

Explanation: Inheritance allows a new class (subclass) to inherit properties and behavior (methods) from an existing class (superclass).

Q5. Which keyword is used to inherit a class in Python?

a) extends

b) inherit

c) superclass

d) class

Answer: a

Explanation: In Python, the extends keyword is used for inheritance. The subclass extends the superclass.

Q6. What is encapsulation in OOP?

a) Hiding the implementation details of an object

b) Making an object public

c) Exposing private data of an object

d) Limiting the number of objects

Answer: a

Explanation: Encapsulation is the bundling of data (attributes) and methods (functions) that operate on the data, hiding the implementation details from the user.

Q7. Which access specifier in Python indicates that an attribute should not be accessed directly from outside the class?

a) public

b) private

c) protected

d) hidden

Answer: b

Explanation: In Python, an attribute or method with a name starting with two underscores __ is considered private and should not be accessed directly from outside the class.

Q8. What is polymorphism in OOP?

a) The ability of an object to take on many forms

b) The ability to inherit from multiple classes

c) The ability to have multiple constructors

d) The ability to have multiple instances of an object

Answer: a

Explanation: Polymorphism refers to the ability of an object to take on many forms. It allows objects of different classes to be treated as objects of a common superclass.

Q9. Which OOP principle allows methods in a subclass to have the same name as methods in its superclass, but with different implementations?

a) Inheritance

b) Polymorphism

c) Encapsulation

d) Abstraction

Answer: b

Explanation: Polymorphism allows methods in a subclass to have the same name as methods in its superclass, but with different implementations.

Q10. What is the process of defining a new class based on an existing class called?

a) Polymorphism

b) Inheritance

c) Abstraction

d) Encapsulation

Answer: b

Explanation: Inheritance is the process of defining a new class based on an existing class, inheriting its attributes and methods.

Q11. What is a superclass in inheritance?

a) A class that does not have any parent class

b) A class from which other classes inherit

c) A class that can inherit from multiple classes

d) A class with private attributes only

Answer: b

Explanation: A superclass (or parent class) is a class from which other classes inherit properties and behaviors.

Q12. What is a subclass in inheritance?

a) A class that does not have any child class

b) A class that has a parent class

c) A class that cannot have private attributes

d) A class that can inherit from multiple classes

Answer: a

Explanation: A subclass (or child class) is a class that inherits properties and behaviors from a superclass.

Q13. Which of the following is true about the super() function in Python?

a) It calls the superclass’s constructor

b) It calls the subclass’s constructor

c) It is used to create a new object

d) It is used to access private members

Answer: a

Explanation: The super() function in Python is used to call methods and constructors of the superclass.

Q14. What is method overriding in OOP?

a) Creating a new method with the same name as a method in the superclass

b) Deleting a method from a superclass

c) Hiding a method in the superclass

d) Replacing a method in the superclass with a new implementation in the subclass

Answer: d

Explanation: Method overriding occurs when a subclass provides a specific implementation of a method that is already defined in its superclass.

Q15. What is an abstract class in Python?

a) A class that cannot be instantiated

b) A class with only private methods

c) A class with only public methods

d) A class with no methods

Answer: a

Explanation: An abstract class in Python is a class that cannot be instantiated and is used as a base class for other classes.

Q16. How do you define an abstract class in Python?

a) By using the abstract keyword

b) By using the abstract class statement

c) By importing the abc module and using @abstractmethod decorator

d) By using the virtual keyword

Answer: c

Explanation: Abstract classes in Python are defined by importing the abc module and using the @abstractmethod decorator.

Q17. What is an interface in Python?

a) A class that cannot be inherited

b) A blueprint of a class without any implementation

c) A class with only private methods

d) A class with only public methods

Answer: b

Explanation: An interface in Python is a blueprint of a class that defines a set of methods without any implementation.

Q18. Which OOP principle allows a class to have multiple methods with the same name but different parameters?

a) Inheritance

b) Polymorphism

c) Encapsulation

d) Abstraction

Answer: b

Explanation: Polymorphism allows a class to have multiple methods with the same name but different parameters or behavior.

Q19. What is composition in OOP?

a) A way to create objects of one class within another class

b) A way to create multiple instances of a class

c) A way to inherit from multiple classes

d) A way to override superclass methods in a subclass

Answer: a

Explanation: Composition is a design technique in OOP where objects of one class are created within another class.

Q20. What is the purpose of the __init__ method in Python classes?

a) To define private attributes

b) To define public attributes

c) To initialize object state

d) To delete an object

Answer: c

Explanation: The __init__ method is a special method in Python classes used to initialize newly created objects with initial values.

Q21. Which keyword is used to define a method in a Python class?

a) method

b) def

c) define

d) function

Answer: b

Explanation: The def keyword is used to define a method within a Python class.

Q22. What does the self keyword represent in Python class methods?

a) It represents the superclass

b) It represents the subclass

c) It represents the current object instance

d) It represents the class itself

Answer: c

Explanation: In Python class methods, self represents the current object instance and allows access to its attributes and methods.

Q23. What does the __str__ method do in Python?

a) Converts an object to a string

b) Converts a string to an object

c) Compares two objects

d) Initializes an object

Answer: a

Explanation: The __str__ method in Python is a special method used to return a string representation of an object.

Q24. Which method is called when an object is deleted?

a) __delete__

b) __remove__

c) __del__

d) __destroy__

Answer: c

Explanation: The __del__ method is called when an object is deleted or garbage-collected in Python.

Q25. What does the isinstance() function do in Python?

a) Checks if an object is an instance of a specific class

b) Checks if an object is a subclass of a specific class

c) Checks if two objects are equal

d) Checks if two objects are the same instance

Answer: a

Explanation: The isinstance() function in Python checks if an object is an instance of a specific class or a subclass.

Q26. What does the issubclass() function do in Python?

a) Checks if an object is an instance of a specific class

b) Checks if an object is a subclass of a specific class

c) Checks if two objects are equal

d) Checks if two objects are the same instance

Answer: b

Explanation: The issubclass() function in Python checks if a class is a subclass of another class.

Q27. What is the purpose of the @staticmethod decorator in Python?

a) To create a static method that can access class attributes

b) To create a method that can access instance attributes

c) To create a class method that can access instance attributes

d) To create a method that can access both class and instance attributes

Answer: a

Explanation: The @staticmethod decorator in Python is used to define a static method that does not have access to instance attributes.

Q28. What is the purpose of the @classmethod decorator in Python?

a) To create a static method that can access class attributes

b) To create a method that can access instance attributes

c) To create a class method that can access class attributes

d) To create a method that can access both class and instance attributes

Answer: c

Explanation: The @classmethod decorator in Python is used to define a class method that has access to class attributes.

Q29. What does the super() function do in Python?

a) Calls the superclass’s method

b) Calls the subclass’s method

c) Creates a new object

d) Deletes an object

Answer: a

Explanation: The super() function in Python is used to call methods of a superclass from a subclass.

Q30. What does the term “method resolution order” (MRO) refer to in Python?

a) The order in which methods are defined in a class

b) The order in which methods are called in a class

c) The order in which multiple inheritance searches for a method

d) The order in which classes are defined in a module

Answer: c

Explanation: Method Resolution Order (MRO) in Python refers to the order in which multiple inheritance searches for a method or attribute.

Q31. What does the following Python code represent?

class Student:
 def __init__(self, name, age):
 self.name = name
 self.age = age

 def display_info(self):
 print("Name:", self.name)
 print("Age:", self.age)

student1 = Student("John", 20)
student1.display_info()

a) Definition of a Student class with attributes name and age

b) Creation of a Student object student1 with name “John” and age 20

c) Displaying information about the student

d) All of the above

Answer: d

Explanation: This code defines a Student class with __init__ method to set name and age, and a method display_info to print student information. It creates a Student object student1 with name “John” and age 20, then displays its information by calling display_info().

Q32. What will be the output of the following code?

class Shape:
 def __init__(self, sides):
 self.sides = sides

 def display_sides(self):
 print("Number of sides:", self.sides)

class Triangle(Shape):
 def __init__(self, side1, side2, side3):
 super().__init__(3)
 self.side1 = side1
 self.side2 = side2
 self.side3 = side3

 def display_area(self):
 s = (self.side1 + self.side2 + self.side3) / 2
 area = (s * (s - self.side1) * (s - self.side2) * (s - self.side3)) ** 0.5
 print("Area of the triangle:", area)

triangle1 = Triangle(3, 4, 5)
triangle1.display_sides()
triangle1.display_area()

a) Number of sides: 3 Area of the triangle: 6.0

b) Number of sides: 3 Area of the triangle: 7.5

c) Number of sides: 4 Area of the triangle: 6.0

d) Number of sides: 4 Area of the triangle: 7.5

Answer: a

Explanation: The code defines a Shape class with __init__ method for sides and a method display_sides to print the number of sides. It then defines a Triangle subclass that inherits from Shape, sets the number of sides to 3, and calculates the area based on side lengths. When a Triangle object triangle1 is created with sides 3, 4, and 5, it prints the number of sides and the area, which is 6.0 for this case.

Q33. What will be the output of the following code?

class Student:
 def __init__(self, name, roll_number):
 self.name = name
 self.roll_number = roll_number

 def display_student(self):
 print("Name:", self.name)
 print("Roll Number:", self.roll_number)

student1 = Student("Alice", 101)
student1.display_student()

a) Name: Alice Roll Number: 101

b) Alice 101

c) Student: Alice ID: 101

d) Name: Student Roll Number: Alice 101

Answer: a

Explanation: The code defines a Student class with __init__ method to set name and roll_number, and a method display_student to print student information. It creates a Student object student1 with name “Alice” and roll number 101, then displays its information by calling display_student().

Congratulations on completing the Python OOPs Concepts MCQs! Object-Oriented Programming is a fundamental concept in Python, allowing you to create efficient and scalable code by organizing data and behavior into classes and objects. By mastering OOP concepts such as inheritance, encapsulation, and polymorphism, you gain the ability to design and implement complex and reusable software systems. Keep practicing and experimenting with Python’s OOP functionalities to become proficient in building robust and maintainable applications. If you have any questions or want to delve deeper into any topic, don’t hesitate to continue your learning journey. Happy coding!

You can also enroll in our free Python Course Today!

Read our more articles related to MCQs in Python:

My name is Ayushi Trivedi. I am a B. Tech graduate. I have 3 years of experience working as an educator and content editor. I have worked with various python libraries, like numpy, pandas, seaborn, matplotlib, scikit, imblearn, linear regression and many more. I am also an author. My first book named #turning25 has been published and is available on amazon and flipkart. Here, I am technical content editor at Analytics Vidhya. I feel proud and happy to be AVian. I have a great team to work with. I love building the bridge between the technology and the learner.

Login to continue reading and enjoy expert-curated content.

Free Courses

Generative AI - A Way of Life

Explore Generative AI for beginners: create text and images, use top AI tools, learn practical skills, and ethics.

Getting Started with Large Language Models

Master Large Language Models (LLMs) with this course, offering clear guidance in NLP and model training made simple.

Building LLM Applications using Prompt Engineering

This free course guides you on building LLM apps, mastering prompt engineering, and developing chatbots with enterprise data.

Improving Real World RAG Systems: Key Challenges & Practical Solutions

Explore practical solutions, advanced retrieval strategies, and agentic RAG systems to improve context, relevance, and accuracy in AI-driven applications.

Microsoft Excel: Formulas & Functions

Master MS Excel for data analysis with key formulas, functions, and LookUp tools in this comprehensive course.

Responses From Readers

Flagship Programs

GenAI Pinnacle Program| GenAI Pinnacle Plus Program| AI/ML BlackBelt Program| Agentic AI Pioneer Program

Free Courses

Generative AI| DeepSeek| OpenAI Agent SDK| LLM Applications using Prompt Engineering| DeepSeek from Scratch| Stability.AI| SSM & MAMBA| RAG Systems using LlamaIndex| Building LLMs for Code| Python| Microsoft Excel| Machine Learning| Deep Learning| Mastering Multimodal RAG| Introduction to Transformer Model| Bagging & Boosting| Loan Prediction| Time Series Forecasting| Tableau| Business Analytics| Vibe Coding in Windsurf| Model Deployment using FastAPI| Building Data Analyst AI Agent| Getting started with OpenAI o3-mini| Introduction to Transformers and Attention Mechanisms

Popular Categories

AI Agents| Generative AI| Prompt Engineering| Generative AI Application| News| Technical Guides| AI Tools| Interview Preparation| Research Papers| Success Stories| Quiz| Use Cases| Listicles

Generative AI Tools and Techniques

GANs| VAEs| Transformers| StyleGAN| Pix2Pix| Autoencoders| GPT| BERT| Word2Vec| LSTM| Attention Mechanisms| Diffusion Models| LLMs| SLMs| Encoder Decoder Models| Prompt Engineering| LangChain| LlamaIndex| RAG| Fine-tuning| LangChain AI Agent| Multimodal Models| RNNs| DCGAN| ProGAN| Text-to-Image Models| DDPM| Document Question Answering| Imagen| T5 (Text-to-Text Transfer Transformer)| Seq2seq Models| WaveNet| Attention Is All You Need (Transformer Architecture) | WindSurf| Cursor

Popular GenAI Models

Llama 4| Llama 3.1| GPT 4.5| GPT 4.1| GPT 4o| o3-mini| Sora| DeepSeek R1| DeepSeek V3| Janus Pro| Veo 2| Gemini 2.5 Pro| Gemini 2.0| Gemma 3| Claude Sonnet 3.7| Claude 3.5 Sonnet| Phi 4| Phi 3.5| Mistral Small 3.1| Mistral NeMo| Mistral-7b| Bedrock| Vertex AI| Qwen QwQ 32B| Qwen 2| Qwen 2.5 VL| Qwen Chat| Grok 3

AI Development Frameworks

n8n| LangChain| Agent SDK| A2A by Google| SmolAgents| LangGraph| CrewAI| Agno| LangFlow| AutoGen| LlamaIndex| Swarm| AutoGPT

Data Science Tools and Techniques

Python| R| SQL| Jupyter Notebooks| TensorFlow| Scikit-learn| PyTorch| Tableau| Apache Spark| Matplotlib| Seaborn| Pandas| Hadoop| Docker| Git| Keras| Apache Kafka| AWS| NLP| Random Forest| Computer Vision| Data Visualization| Data Exploration| Big Data| Common Machine Learning Algorithms| Machine Learning| Google Data Science Agent
👁 Av Logo White

Continue your learning for FREE

Forgot your password?
👁 Av Logo White

Enter OTP sent to

Edit

Wrong OTP.

Enter the OTP

Resend OTP

Resend OTP in 45s

👁 Popup Banner
👁 AI Popup Banner