Skip to content

Commit 5b3242b

Browse files
Merge pull request #32 from codewithdhruba01/codewithdhruba01-patch-1
add practice question
2 parents acffe26 + 12ecd60 commit 5b3242b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

14_OOPS/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,48 @@ b.start() # Output: Bike starts with a button
157157

158158
---
159159

160+
### 1. Create a Class and Object
161+
162+
Task: Create a class `Car` with attributes like `brand` and `model`. Create an object of the class and print its details.
163+
164+
### 2. Class with Method
165+
166+
Task: Create a class `Calculator` with methods `add`, `subtract`, `multiply`, and `divide`. Create an object and call each method with example numbers.
167+
168+
### 3. Constructor (`__init__`) Usage
169+
170+
Task: Create a class `Student` with a constructor that takes `name` and `age` as arguments. Create multiple objects and print their information.
171+
172+
### 4. Class with Class Variable and Instance Variable
173+
174+
Task: Create a class `Employee` with a **class variable** `company_name` and **instance variables** `name` and `salary`. Create multiple objects and show the difference between class and instance variables.
175+
176+
### 5. Inheritance (Single Level)
177+
178+
Task: Create a base class `Person` with attributes `name` and `age`. Derive a class `Teacher` that adds an attribute `subject`. Create an object of `Teacher` and print all details using inheritance.
179+
180+
### 6. Multiple Inheritance
181+
182+
Task: Create two parent classes `A` and `B`, each having a different method. Create a child class `C` that inherits both `A` and `B`, and call methods from both parents using an object of `C`.
183+
184+
### 7. Method Overriding
185+
186+
Task: Create a parent class `Animal` with a method `speak()`. Create a child class `Dog` that overrides the `speak()` method to print “Bark”. Create another class `Cat` that overrides it to print “Meow”. Demonstrate polymorphism by calling `speak()` on different objects.
187+
188+
### 8. Encapsulation (Private Variables)
189+
190+
Task: Create a class `BankAccount` with a private variable `__balance`. Add methods `deposit()` and `withdraw()`. Demonstrate how private variables work and how to update them using methods.
191+
192+
### 9. Abstraction using Abstract Class
193+
194+
Task: Create an abstract class `Shape` with an abstract method `area()`. Then create subclasses `Circle` and `Rectangle` that implement the `area()` method. Use objects to calculate area for both shapes.
195+
196+
### 10. Operator Overloading
197+
198+
Task: Create a class `Vector` with `x` and `y` coordinates. Overload the `+` operator so that you can add two `Vector` objects like `v1 + v2` and get a new `Vector` as the result.
199+
200+
---
201+
160202
## OOP Advantages in Python
161203
✔ Code reusability (Inheritance)
162204
✔ Better data security (Encapsulation)

0 commit comments

Comments
 (0)