You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 14_OOPS/README.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -157,6 +157,48 @@ b.start() # Output: Bike starts with a button
157
157
158
158
---
159
159
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.
0 commit comments