0% found this document useful (0 votes)
6 views14 pages

Python OOPS Interview Question - GeeksforGeeks

Uploaded by

bhavaniprakasht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

Python OOPS Interview Question - GeeksforGeeks

Uploaded by

bhavaniprakasht
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

Search...

Python OOPS Interview question


Last Updated : 18 Dec, 2024

In Python, Object-Oriented Programming (OOP) allows developers to


structure their code in a more efficient, scalable, and maintainable way
by using classes and objects. These objects can have attributes (data)
and methods (functions) that represent both the state and behaviour of
an entity. Python OOP provides a powerful approach to managing
complex systems and applications.

Table of Content
Basic OOPS Interview Questions
Intermediate Python OOPs Interview Questions
Advanced Python Interview OOPs Questions

In this article, we will explore common Object-Oriented


Programming(OOP) interview questions related to Python. Let’s
explore some key OOP interview questions that will help you master
Python’s OOP features.

Basic OOPS Interview Questions

1. What is Object-Oriented Programming (OOP)?

Object-Oriented Programming (OOP) is a fundamental paradigm in


Python which is designed to model real-world entities through classes
and objects. It offers features like encapsulation, inheritance,
polymorphism, and abstraction enabling developers to write reusable,
modular, and maintainable code.

2. What are the key features of OOP?

The key features of oop are:


https://www.geeksforgeeks.org/python/python-oops-interview-question/ 1/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

Encapsulation: Bundles data and methods within a class, hiding


internal details from outside access.
Abstraction: Hides complex implementation details and exposes
only necessary functionality.
Inheritance: Allows a new class to inherit properties and methods
from an existing class.
Polymorphism: Enables a single interface to represent different
behaviors.

3. What is a class and an object in Python?

Class: A blueprint for creating objects, defining their properties and


methods.
Object: An instance of a class.

Example:

class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed

def speak(self):
print(f"{self.name} says Woof!")

dog1 = Dog("Buddy", "Golden Retriever")


dog1.speak()

4. What is the difference between a class and an instance?

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 2/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

Class: Defines the structure and behavior (attributes and methods).


Instance: A concrete occurrence of a class with actual data

5. What is the __init__ method in Python?

The __init__ method is a constructor used to initialize an object’s


attributes when it is created and it is also known as constructor. The
__init__ method is part of Python's object-oriented programming (OOP)
mechanism and is used to set up the initial state of the object when it is
instantiated.

Example:

class Person:
def __init__(self, name):
self.name = name
p = Person("Alice")

6. What is self in Python classes?

self is a reference to the current instance of the class. It is used to


access attributes and methods of the class. When you define a method
inside a class, the first parameter of the method is always self, which
allows the method to refer to the object (or instance) on which the
method was called.

7. What is the difference between instance variables and class


variables?

Instance variables: Instance variables unique to each object.


Class variables: Shared among all objects of a class.

Example:

class Demo:
class_var = "shared" # class variable

def __init__(self, val):

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 3/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

self.instance_var = val # instance variable

8. What is inheritance in Python?

Inheritance allows a class to inherit attributes and methods from


another class. Inheritance enables the child class to inherit the
properties (attributes) and behaviors (methods) of the parent class, and
it can also define its own additional attributes and methods or override
existing ones.

Example:

# Define the Parent class (base class)


class Parent:
pass

# Define the Child class that inherits from Parent class


class Child(Parent):
pass

9. What is method overloading in Python?

Method overloading in Python refers to the ability to define multiple


methods with the same name but with different parameters (different
numbers or types of arguments).

Example:

def greet(name="Guest"):

# Print a greeting message, using the 'name' argument.


print(f"Hello, {name}")

10. What is method overriding in Python?

Method overriding allows a subclass to provide a specific


implementation of a method that is already defined in its superclass.
This means that the subclass can "override" the behavior of the method

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 4/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

inherited from the parent class, providing a different version that is more
suitable for the subclass.

Example:

class Parent:
def show(self):
print("Parent")

class Child(Parent):
def show(self): # Method overriding
print("Child")

Intermediate Python OOPs Interview Questions

11. What is polymorphism in Python?

Polymorphism allows objects to be treated as instances of their parent


class, enabling different implementations for the same interface. It
enables a single function, method, or operator to work with different
types of objects in a way that is determined at runtime, allowing code to
be more flexible and reusable.

Example:

class Bird:
# Method to make a sound for the Bird class
def speak(self):
print("Chirp")

class Dog:
# Method to make a sound for the Dog class
def speak(self):
print("Bark")

12. What is encapsulation, and how does Python achieve it?

Encapsulation is one of the fundamental principles of OOP. It allows the


internal representation of an object to be hidden from the outside world
and exposes only what is necessary through a controlled interface.

Example:
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 5/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

class Example:
def __init__(self):
self.__private_var = 42

13. What is the super() function in Python?

super() allows access to methods of the parent class and it’s often used
to call the parent class’s constructor.

Example:

class A:
def method(self):
print("Method in class A")

class B(A):
def method(self):
super().method() # Call method from class A
print("Method in class B")

class C(A):
def method(self):
super().method() # Call method from class A
print("Method in class C")

14. What are abstract classes in Python?

Abstract class is a class that serves as a blueprint for other classes. It


defines a structure that derived classes must follow but does not
provide full implementation, abstract classes cannot be instantiated
directly which means they are meant to be subclassed.

Example:

from abc import ABC, abstractmethod


class Animal(ABC):
@abstractmethod
def sound(self):
pass

15. What is the difference between is and ==?


https://www.geeksforgeeks.org/python/python-oops-interview-question/ 6/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

'is' checks if two objects are the same instance(identity) and '==' checks
if the two objects have the same value(equality).

16. What is multiple inheritance in Python?

Multiple inheritance allows a subclass to inherit features from multiple


parent classes, making it more versatile and capable of combining
behaviors from different sources.

class ChildClass(ParentClass1, ParentClass2, ...):


# Class body

17. What is the diamond problem in multiple inheritance? How


does Python handle it?

The Diamond Problem in multiple inheritance is a classic issue that


arises when a class inherits from two classes that both inherit from a
common ancestor. The problem occurs because, in such a scenario, it's
unclear which version of the inherited method should be invoked when
the method is called on the subclass.

18. What are class methods in Python?

Class methods are defined with the @classmethod decorator and take 'cls'
(class reference) as their first argument.

class Demo:
@classmethod
def info(cls):
print("Class Method")

19. What is the difference between staticmethod and classmethod?

In Python, both @staticmethod and @classmethod @staticmethod and


@classmethod are used to define methods that are not bound to the
instance of the class (i.e., they can be called on the class itself).

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 7/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

Aspect staticmethod classmethod

Not bound to either


Bound to the class, not
Binding the instance or the
the instance.
class.

Does not take self or Takes cls as the first


First Argument cls as the first argument (refers to the
argument. class).

Access to Cannot access or Can access and modify


Class/Instance modify instance or class variables (but not
Variables class variables. instance variables).
Python Course Python Tutorial Interview Questions Python Quiz Python Sign In

Can be called on the Can be called on the class


Call
class or an instance. or an instance.

20. What are magic methods in Python?

Magic methods(dunder methods) start and end with double


underscores providing operator overloading and custom behaviors.

Examples: __str__, __len__ and , __init__ so on...

Advanced Python Interview OOPs Questions

21. How does Python handle garbage collection?

Python uses automatic garbage collection to manage memory by


identifying and removing unused objects and It employs reference
counting and a cyclic garbage collector.

22. What is metaclass in Python?

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 8/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

A metaclass is a class of a class that defines how classes behave and


classes are instances of metaclasses. Essentially, metaclasses define
the "rules" for building classes, much like a class defines the rules for
creating objects.

Example:

class Meta(type):
# This is an empty metaclass that inherits from 'type'
pass

class Demo(metaclass=Meta):
# The 'metaclass=Meta' instructs Python to use the 'Meta' metac
pass

23. How is data hiding implemented in Python?

Data hiding is implemented using private attributes (__attribute) and


even though it is not completely hidden, it is still difficult to access
without name mangling.

24.What is the purpose of __slots__ in Python classes?

__slots__ attribute limits the attributes that can be added to an instance


improving memory usage.

Example:

class Example:
__slots__ = ['name', 'age']

25. What is the Global Interpreter Lock (GIL) and its impact on
Python OOP?

The GIL ensures only one thread executes Python bytecode at a time
affecting multithreaded programs. Its purpose is to prevent multiple
native threads from executing Python bytecode at the same time,
ensuring thread safety in Python's memory management system. .

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 9/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

26.How do you achieve operator overloading in Python?

Operator overloading is achieved using magic methods like __add__ and


__eq__.

Example:

class Point:
def __add__(self, other):
return Point(self.x + other.x)

26. What is the difference between shallow copy and deep copy
in Python?

In Python, shallow copy and deep copy are used to create copies of
objects. They differ in how they handle nested objects, such as lists
within lists or objects containing other objects. A shallow copy creates
a new object but does not copy the nested objects inside it and A deep
copy creates a new object and recursively copies all objects within it,
including nested objects.

27. What is the difference between composition and inheritance?

Composition and inheritance are two fundamental object-oriented


programming (OOP) techniques for creating relationships between
classes. The main difference between inheritance and composition is
that:

Inheritance: "Is-a" relationship (e.g., a Car is-a Vehicle).


Composition: "Has-a" relationship (e.g., a Car has-a Engine).

28. How do you implement design patterns like Singleton in


Python?

Singleton ensures only one instance of a class exists. it design pattern


ensures that a class has only one instance and provides a global point
of access to it.

Example:
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 10/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

class Singleton:
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance

29. Explain Python’s MRO with an example.

Python's , determines the order in which classes are searched when


calling a method or accessing an attribute. It is crucial in object-oriented
programming, especially when dealing with multiple inheritance.

Example:

class A:
# Class A is a base class with no methods or attributes
pass

class B(A):
# Class B inherits from A
pass

class C(A):
# Class C also inherits from A
pass

class D(B, C):


# Class D inherits from both B and C
pass
print(D.mro())

30. How would you identify the MRO of a class


programmatically?

We can identify the Method Resolution Order (MRO) of a class


programmatically in Python using the mro() Method or by using the
__mro__ attribute.

Using the mro() method: This method returns a list of classes in the
order they are checked for method resolution.
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 11/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

Using the __mro__ attribute: This attribute directly provides the MRO
as a tuple of classes.

Comment More info Next Article


Top 30 Python Dictionary
Campus Training Program Interview Questions

Corporate & Communications Address:


A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Pradesh
(201305)

Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida, Gautam
Buddh Nagar, Uttar Pradesh, 201305

Advertise with us

Company Explore
About Us Job-A-Thon
Legal Offline Classroom Program
Privacy Policy DSA in JAVA/C++
Careers Master System Design
In Media Master CP
Contact Us Videos
Corporate Solution
Campus Training Program

Tutorials DSA
Python Data Structures
Java Algorithms

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 12/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

C++ DSA for Beginners


PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android

Data Science & ML Web Technologies


Data Science With Python HTML
Machine Learning CSS
ML Maths JavaScript
Data Visualisation TypeScript
Pandas ReactJS
NumPy NextJS
NLP NodeJs
Deep Learning Bootstrap
Tailwind CSS

Python Tutorial Computer Science


Python Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps System Design


Git High Level Design
AWS Low Level Design
Docker UML Diagrams
Kubernetes Interview Guide
Azure Design Patterns
GCP OOAD
DevOps Roadmap System Design Bootcamp
Interview Questions

School Subjects Databases


Mathematics SQL
Physics MYSQL
Chemistry PostgreSQL
Biology PL/SQL
Social Science MongoDB
English Grammar

Preparation Corner More Tutorials


Company-Wise Recruitment Process Software Development
Aptitude Preparation Software Testing
Puzzles Product Management

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 13/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks

Company-Wise Preparation Project Management


Linux
Excel
All Cheat Sheets

Courses Programming Languages


IBM Certification Courses C Programming with Data Structures
DSA and Placements C++ Programming Course
Web Development Java Programming Course
Data Science Python Full Course
Programming Languages
DevOps & Cloud

Clouds/Devops GATE 2026


DevOps Engineering GATE CS Rank Booster
AWS Solutions Architect Certification GATE DA Rank Booster
Salesforce Certified Administrator Course GATE CS & IT Course - 2026
GATE DA Course 2026
GATE Rank Predictor

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/python/python-oops-interview-question/ 14/14

You might also like