DEV Community

Guru prasanna
Guru prasanna

Posted on

OOPS - Interview Questions in python

OOPs (Object-Oriented Programming) Interview Questions in Python

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

OOP is a programming paradigm based on the concept of objects, which contain data (attributes) and methods (functions). It allows for code reusability, modularity, and abstraction.

Key principles of OOP:

  • Encapsulation : Hiding data inside a class and restricting direct access.
  • Abstraction : Hiding implementation details and exposing only necessary parts.
  • Inheritance : Reusing code by creating a new class from an existing one.
  • Polymorphism : Having multiple forms of the same method (overloading & overriding).

2) What is a Class and an Object?

  • A class is a blueprint/template for creating objects.
  • An object is an instance of a class.

3) What is Encapsulation?

--> Encapsulation is the process of hiding data within a class and only allowing controlled access via methods.
--> In Python, we use private attributes (__varname) to enforce encapsulation.

4) What is Inheritance?

Inheritance allows a class (child class) to inherit attributes and methods from another class (parent class).

Types of inheritance:

  • Single Inheritance → A child class inherits from a single parent class.
  • Multiple Inheritance → A child class inherits from multiple parent classes.
  • Multilevel Inheritance → A child class inherits from a parent class, which itself inherits from another parent.
  • Hierarchical Inheritance → Multiple child classes inherit from a single parent class.
  • Hybrid Inheritance → A mix of two or more types of inheritance (e.g., multiple + multilevel).

5) What is Polymorphism?

Polymorphism allows different classes to use the same method name but behave differently.

6) What is Abstraction?

--> Abstraction means hiding implementation details and exposing only the required functionalities using abstract classes.
--> Python provides ABC (Abstract Base Class) to achieve abstraction.

7) What is the difference between Method Overloading and Method Overriding?

Method overloading : Same method name with different parameters in the same class.
Method Overriding : Same method name and same parameters in a parent-child relationship (Inheritance).

AWS Q Developer image

Your AI Code Assistant

Ask anything about your entire project, code and get answers and even architecture diagrams. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Start free in your IDE

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

If you found this post useful, please drop a ❤️ or leave a kind comment!

Okay