Commit 1234783
committed
feat: Add basic constructor demo with static methods in class Constructor [constructor-basics-static]
🔑 Key: constructor-basics-static
🧠 Logic:
- Defined a class named `Constructor` to demonstrate:
• ✅ A **no-argument constructor** — prints a message when object is instantiated.
• ✅ Two **static methods** (`puton()` and `takeOFF()`) representing actions on a Shirt.
- Instantiating an object (`new Constructor()`) triggers the constructor automatically.
- Static method `puton()` is called using object (though ideally should be `Constructor.puton()`).
📌 Concepts Demonstrated:
- 🧱 **Constructor Rules**:
• Same name as class.
• No return type, not even `void`.
• Used to initialize objects at creation.
- 🧼 **Static Methods**:
• Belong to class, not to instances.
• Can be called without creating object (e.g., `Constructor.puton()`).
🧪 Notes:
- Calling `takeOFF()` was commented out but can be used similarly.
- The constructor acts like an **object initializer**, even if no values are passed or set.
🧠 Analogy:
- Think of constructor as a “birth certificate” that sets up an object during its birth.
📎 Educational Value:
- Great minimal template for explaining object lifecycle and class-vs-instance behaviors.
Signed-off-by: Somesh diwan <[email protected]>1 parent 6e0ad9b commit 1234783
1 file changed
+19
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 1 | | |
10 | | - | |
11 | 2 | | |
12 | 3 | | |
13 | 4 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 5 | + | |
| 6 | + | |
17 | 7 | | |
18 | 8 | | |
19 | 9 | | |
20 | | - | |
21 | | - | |
| 10 | + | |
22 | 11 | | |
23 | 12 | | |
24 | 13 | | |
25 | | - | |
26 | | - | |
| 14 | + | |
27 | 15 | | |
28 | 16 | | |
29 | | - | |
30 | | - | |
| 17 | + | |
31 | 18 | | |
32 | 19 | | |
33 | 20 | | |
34 | 21 | | |
35 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
0 commit comments