A.
Basics of OOP
1. What is Object Oriented Programming?
2. Why is OOP preferred over procedural programming?
3. List and explain the four main features of OOP.
4. Define class and object with suitable examples.
5. What is a blueprint in OOP?
6. Differentiate between class and object.
7. What is an instance of a class?
8. How many objects can be created from a class?
9. Is Python purely object-oriented? Justify.
B. Class and Object in Python
10. Write the syntax for defining a class in Python.
11. What is the purpose of __init__() method?
12. Is __init__() compulsory? Explain.
13. What is self? Why is it required?
14. Can a class have multiple constructors in Python?
15. How are attributes accessed outside the class?
16. What are instance variables?
17. What happens if self is not used inside a class?
18. Explain the lifecycle of an object in Python.
C. Methods in a Class
19. What is a method?
20. Difference between method and function.
21. What are instance methods?
22. What is the difference between local variables and instance variables?
23. Can a class have more than one method?
24. How do methods access object data?
25. Explain with example how methods are called using objects.
D. Special Methods (__str__, __init__)
26. What is a special (magic) method in Python?
27. Explain the purpose of __str__() method.
28. What happens if __str__() is not defined?
29. Differentiate between __str__() and __repr__().
30. Is __str__() an inbuilt method?
31. When is __str__() automatically called?
E. Mutability and Objects
32. What does it mean when an object is mutable?
33. Are objects of user-defined classes mutable? Explain.
34. Differentiate between mutable and immutable objects.
35. Give examples of mutable and immutable data types.
36. Explain mutability with reference to object attributes.
1. What is inheritance in Python?
2. Why is inheritance used?
3. What is a parent class?
4. What is a child class?
5. Write the syntax for inheritance in Python.
6. What is the role of super()?
7. Can a child class access parent class variables?
8. What happens if parent class constructor is not called?
9. Explain “IS-A relationship” with example.
Polymorphism
51. Define polymorphism.
52. Explain polymorphism with real-life example.
53. How is polymorphism achieved in Python?
54. Explain method overriding.
55. What happens if child class does not override parent method?
56. Explain duck typing in Python.
57. Is inheritance compulsory for polymorphism?
58. Give an example of polymorphism without inheritance.
Operator Overloading
59. What is operator overloading?
60. Why is operator overloading required?
61. Which special method is used for + operator?
62. How does Python internally handle obj1 + obj2?
63. Can we overload all operators in Python?
64. Write an example of operator overloading for +.
65. Explain advantages of operator overloading.
66. Explan __mul and __rmul__ functions to overload multiplication operator.
. Conceptual / Application-Oriented Questions
73. Why are classes said to improve code organization?
74. How does OOP improve real-world modeling?
75. Explain how inheritance and polymorphism work together.
76. Why are objects preferred over global variables?
77. Can a function return an object? Explain.
78. Can objects be passed as arguments to functions?
79. Why is encapsulation important? (conceptual)
80. Give a real-world example combining class, inheritance, and polymorphism.
A. Class and Object (Basic)
1. Write a Python program to define a class Student with attributes name, roll number, and marks.
Create an object and display student details.
2. Define a class Rectangle with attributes length and breadth. Create methods to compute and
display area and perimeter.
3. Write a Python program to define a class Employee with attributes emp_id, name, and salary.
Display annual salary.
4. Create a class Book with attributes title, author, and price. Read details for two books and display
the costliest book.
B. Constructor and Methods
5. Write a Python program using a constructor to initialize a class Car with brand, model, and price.
Display the details.
6. Define a class BankAccount with account number and balance. Include methods deposit() and
withdraw().
7. Write a Python program to define a class Time with hours and minutes. Write a method to add
two time objects.
C. Objects as Arguments and Return Values
8. Define a class Complex and write a function to add two complex number objects and return the
result.
9. Write a Python program where a function accepts a list of Student objects and returns the
topper.
10. Define a class Point and write a function that takes two Point objects and returns the distance
between them.
D. Special Methods (__str__)
11. Define a class Point and override the __str__() method to display coordinates in (x, y) format.
12. Write a Python program to define a class Person and override __str__() to display name and age.
E. Mutability Demonstration
13. Write a Python program to show that objects of user-defined classes are mutable.
14. Modify attributes of an object inside a function and show that the changes reflect outside the
function.
Method Overriding (Polymorphism)
18. Write a Python program to demonstrate method overriding using classes Animal, Dog, and Cat.
19. Write a Python program where a child class overrides a method of the parent class and uses
super()
Write a Python program to demonstrate duck typing using two unrelated classes having the
same method name.
Write a Python program to overload the + operator to add two complex number objects.
Write a Python program to overload the > operator to compare marks of two students.
Overload the == operator to compare two objects of a class Book.
1. What is meant by object sameness in Python?
2. Differentiate between identity and equality of objects.
3. What is the difference between is and == operators?
4. Which operator checks whether two variables refer to the same object?
5. Which operator checks whether two objects have the same value?
6. Can two objects be equal but not identical? Explain.
7. Can two objects be identical but not equal? Justify.
8. What is the role of the id() function in object sameness?
9. What does id(obj) represent?
10. Why is object sameness important in mutable objects?
Predict the output for following codes-
1. a = [1, 2, 3]
b=a
print(a is b)
2. a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)
3. x = 1000
y = 1000
print(x is y)
4. s1 = "python"
s2 = "python"
print(s1 is s2)
What does the expression a is b mean?
Why should is not be used to compare values?
When should is be used?
What happens to object identity when a mutable object is modified?
What happens to object identity when an immutable object is modified?
Write a Python program to demonstrate that two lists with same contents are equal
but not identical.
Write a Python program to show object sameness using id() function.
Write a Python program to show difference between assignment and copying of
objects.
Write a Python program to show object identity in user-defined class objects.
Write a Python program to demonstrate that modifying a mutable object affects all
references pointing to it.
Can object sameness be tested for class objects? Explain.
Why is object sameness dangerous with mutable objects?
How can shallow copy and deep copy affect object sameness?
Explain object aliasing with example.
How does object sameness affect function arguments?
Why should care be taken while passing lists to functions?
Explain real-world scenario where object sameness can cause bugs.
Consider the following code. Are p1 and p2 same objects? Justify.
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
p1 = Point(2, 3)
p2 = Point(2, 3)
what will be the output?
p1 = Point(1, 1)
p2 = p1
print(p1 is p2)
x = 1000
y = 1000
print(x is y)
5. print(a is b)