Unit 5: Classes and objects; Object oriented programming terminology - Subjective Questions

INT108 — Python Programming • Practice Questions with Detailed Answers

20 questions

1

Define a class in Python. Explain the general syntax for creating a class with a suitable example.

2

What is an instance object? Describe how instance objects are created and initialized in Python.

3

Explain the purpose of the self parameter in Python classes. What happens if it is omitted from an instance method?

4

Distinguish between instance attributes and class attributes in Python, using an example.

5

Describe different ways of accessing, modifying, adding, and deleting object attributes in Python.

6

Explain the role of the __init__() method. Is it technically responsible for creating an object?

7

Define inheritance. Demonstrate single inheritance in Python and explain its advantages.

8

Describe single, multilevel, hierarchical, and multiple inheritance in Python. Give a short example of each.

9

What is method overriding? Explain how it enables runtime polymorphism with a suitable Python program.

10

Explain the use of super() in inheritance. How can a child class extend a parent class initializer and an overridden method?

11

What is the Method Resolution Order (MRO)? Explain how Python resolves methods in multiple inheritance.

12

Define data hiding in Python. Explain the conventions for public, protected, and private attributes.

13

Explain name mangling for private attributes in Python. Does it provide complete data security?

14

Describe how getter and setter methods can be used to implement controlled access to hidden data.

15

Explain the @property decorator. Write a class that uses a property to validate an attribute.

16

What is function overloading? Explain why conventional compile-time function overloading is not directly supported in Python.

17

Demonstrate how default arguments and variable-length arguments can simulate function overloading in Python.

18

Explain how functools.singledispatch provides type-based function overloading. State its main limitation.

19

Compare method overriding and function overloading in Python.

20

Design a Python class hierarchy for a bank account system that demonstrates object creation, inheritance, method overriding, data hiding, and controlled attribute access.