Python OOPS Interview Question - GeeksforGeeks
Python OOPS Interview Question - GeeksforGeeks
Search...
Table of Content
Basic OOPS Interview Questions
Intermediate Python OOPs Interview Questions
Advanced Python Interview OOPs Questions
Example:
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
def speak(self):
print(f"{self.name} says Woof!")
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 2/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks
Example:
class Person:
def __init__(self, name):
self.name = name
p = Person("Alice")
Example:
class Demo:
class_var = "shared" # class variable
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 3/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks
Example:
Example:
def greet(name="Guest"):
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")
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")
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
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")
Example:
'is' checks if two objects are the same instance(identity) and '==' checks
if the two objects have the same value(equality).
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")
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 7/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 8/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks
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
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
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.
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
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
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.
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
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 13/14
7/15/25, 1:16 PM Python OOPS Interview question - GeeksforGeeks
https://www.geeksforgeeks.org/python/python-oops-interview-question/ 14/14