Python- OOPS python interview questions

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

How to create an empty class in Python?

An empty class is a class that does not have any code defined within its block. It can be created using the pass keyword. However, you can create objects of this class outside the class itself. IN PYTHON THE PASS command does nothing when its executed. it's a null statement.

How are classes created in Python?

Class in Python is created using the class keyword.

How do you do data abstraction in Python?

Data Abstraction is providing only the required details and hiding the implementation from the world. It can be achieved in Python by using interfaces and abstract classes.

Define encapsulation in Python?

Encapsulation means binding the code and the data together. A Python class in an example of encapsulation.

What is monkey patching in Python?

In Python, the term monkey patch only refers to dynamic modifications of a class or module at run-time.

Explain Inheritance in Python with an example.

Inheritance allows One class to gain all the members(say attributes and methods) of another class. Inheritance provides code reusability, makes it easier to create and maintain an application. The class from which we are inheriting is called super-class and the class that is inherited is called a derived / child class. They are different types of inheritance supported by Python: 1.Single Inheritance - where a derived class acquires the members of a single super class. 2.Multi-level inheritance - a derived class d1 in inherited from base class base1, and d2 are inherited from base2. 3.Hierarchical inheritance - from one base class you can inherit any number of child classes 4.Multiple inheritance - a derived class is inherited from more than one base class.

What does an object() do?

It returns a featureless object that is a base for all classes. Also, it does not take any parameters.

Does python support multiple inheritance?

Multiple inheritance means that a class can be derived from more than one parent classes. Python does support multiple inheritance, unlike Java.

What is Polymorphism in Python?

Polymorphism means the ability to take multiple forms. So, for instance, if the parent class has a method named ABC then the child class also can have a method with the same name ABC having its own parameters and variables. Python allows polymorphism.

Does python make use of access specifiers?

Python does not deprive access to an instance variable or function. Python lays down the concept of prefixing the name of the variable, function or method with a single or double underscore to imitate the behavior of protected and private access specifiers.


Set pelajaran terkait

Physics Practice Test - Gravity and Tides

View Set

IGCSE Enterprise - ALL KEY TERMS

View Set

Higher English- The Catcher In the Rye quotes/key points 📖

View Set

Quiz Micro Chap 10 & 11, Midterm 2 Micro 12-12, Quiz 6 micro

View Set