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).

原文链接:OOPS – Interview Questions in python

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
There's only one corner of the universe you can be sure of improving, and that's your own self.
这个宇宙中只有一个角落你肯定可以改进,那就是你自己
评论 抢沙发

请登录后发表评论

    暂无评论内容