0% found this document useful (0 votes)
11 views8 pages

OOPS Interview Questions

The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions of classes, objects, inheritance, encapsulation, and the differences between procedural and object-oriented programming. It also discusses the benefits of OOP in Python, various types of inheritance, method overloading and overriding, and the use of magic methods. Additionally, it covers advanced topics such as memory management, data classes, and the simulation of multiple constructors.

Uploaded by

raviapte84
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)
11 views8 pages

OOPS Interview Questions

The document provides an overview of Object-Oriented Programming (OOP) concepts, including definitions of classes, objects, inheritance, encapsulation, and the differences between procedural and object-oriented programming. It also discusses the benefits of OOP in Python, various types of inheritance, method overloading and overriding, and the use of magic methods. Additionally, it covers advanced topics such as memory management, data classes, and the simulation of multiple constructors.

Uploaded by

raviapte84
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/ 8

🟢 BASIC LEVEL (Conceptual Understanding)

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

Answer:​
Object-Oriented Programming is a programming paradigm that uses "objects" and "classes" to
structure software. The main principles are:

●​ Encapsulation​

●​ Abstraction​

●​ Inheritance​

●​ Polymorphism​

2. What are the benefits of using OOP in Python?

Answer:

●​ Promotes code reusability​

●​ Encourages modular design​

●​ Makes maintenance easier​

●​ Enhances code readability​

●​ Improves data security via encapsulation​

3. Define class and object with an example.

Answer:

●​ A class is a blueprint for creating objects.​


●​ An object is an instance of a class.​

python
CopyEdit
class Car:
def __init__(self, model):
self.model = model

my_car = Car("Tesla")

4. What is the difference between procedural and object-oriented


programming?

Answer:

Procedural Programming Object-Oriented Programming

Follows a top-down approach Follows a bottom-up approach

Functions are the core units Objects and classes are core
units

Less secure More secure (via encapsulation)

5. What is the role of the self keyword in Python?

Answer:​
self refers to the current instance of the class. It is used to access attributes and methods of
the object.

🟡 INTERMEDIATE LEVEL (Practical + Theory)


6. What is inheritance in Python?

Answer:​
Inheritance allows a class (child) to acquire properties and behaviors (methods) of another
class (parent).
python
CopyEdit
class Animal:
def speak(self): print("Animal speaks")

class Dog(Animal):
def bark(self): print("Dog barks")

7. Explain the different types of inheritance in Python.

Answer:

●​ Single Inheritance​

●​ Multiple Inheritance​

●​ Multilevel Inheritance​

●​ Hierarchical Inheritance​

●​ Hybrid Inheritance​

8. What is encapsulation? How is it achieved in Python?

Answer:​
Encapsulation hides internal details and restricts access to them.​
In Python:

●​ Public: var​

●​ Protected: _var​

●​ Private: __var​

9. What is method overloading and overriding in Python?


Answer:

●​ Overriding: Redefining a method in a child class.​

●​ Overloading: Python doesn’t support it directly, but can be mimicked using default
arguments or *args.​

10. Difference between class method, static method, and instance method?

Answer:

Type Acces Use Case


s

Instance self Accesses/updates object


Method state

Class Method cls Accesses/updates class state

Static Method None Utility method, no state


access

11. What is the difference between is-a and has-a relationships?

Answer:

●​ is-a → Inheritance (e.g., Dog is-a Animal)​

●​ has-a → Composition (e.g., Car has-a Engine)​

12. What is the difference between abstract class and interface in Python?

Answer:

●​ Python doesn’t have interfaces like Java.​

●​ Use abstract base classes via abc module.​


●​ Abstract classes can have both abstract and concrete methods.​

python
CopyEdit
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass

🔴 ADVANCED LEVEL (Deep Concepts)


13. What are magic methods (dunder methods) in Python?

Answer:​
Magic methods have double underscores and enable operator overloading and custom
behaviors.​
Examples:

●​ __init__, __str__, __len__, __add__, __eq__​

14. What is MRO (Method Resolution Order)?

Answer:​
MRO defines the order in which Python looks for methods in inheritance hierarchy, especially in
multiple inheritance.​
You can view it using:

python
CopyEdit
print(ClassName.__mro__)

15. What is the purpose of super() function?


Answer:​
super() gives access to methods of a parent class from a child class, often used to call the
constructor or overridden methods.

16. Explain composition with an example.

Answer:​
Composition involves building complex objects using simpler ones by including them as
attributes.

python
CopyEdit
class Engine:
def start(self):
print("Engine started")

class Car:
def __init__(self):
self.engine = Engine()

car = Car()
car.engine.start()

17. What are data classes and why are they used?

Answer:​
Data classes (from dataclasses module) reduce boilerplate code for classes that mainly
store data.

python
CopyEdit
from dataclasses import dataclass

@dataclass
class Person:
name: str
age: int
18. What is the difference between shallow copy and deep copy in Python
OOP?

Answer:

Copy Type Description

Shallow Copy Copies only outer object

Deep Copy Copies outer and all nested


objects
python
CopyEdit
import copy
copy.copy(obj) # Shallow
copy.deepcopy(obj) # Deep

19. How is memory managed in Python OOP?

Answer:​
Python uses automatic memory management through:

●​ Reference counting​

●​ Garbage collection (via the gc module)​

20. Can Python OOP support multiple constructors?

Answer:​
Python does not support multiple constructors directly. However, you can simulate it using
class methods.

python
CopyEdit
class Person:
def __init__(self, name):
self.name = name
@classmethod
def from_dict(cls, data):
return cls(data['name'])

You might also like