Commit b299f90
committed
feat: Demonstrate use of instance variables with unique data per Student object [object-instance-variables]
📌 Core Concept:
Showcases how instance variables store object-specific data and how each instance of a class maintains its own state.
🎓 Program Overview:
- `Student` class:
- Instance Variables: `name`, `gpa` – unique for every object.
- Constructor initializes these per-student attributes.
- `display()` method outputs student-specific information.
- `InstanceVariable` class:
- Creates two `Student` objects with different values.
- Calls `display()` on each to demonstrate data encapsulation.
🧪 Behavior:
- `s1` and `s2` have independent `name` and `gpa` values.
- Modifying one object’s data has no effect on the other.
📌 Key Features:
- Object-level encapsulation using instance variables.
- Demonstrates per-instance memory allocation and behavior.
✅ Useful pattern for:
- Modeling real-world entities with unique properties.
- Understanding how object-oriented programming handles data separation.
Signed-off-by: Somesh diwan <[email protected]>1 parent 9d4185f commit b299f90
File tree
1 file changed
+6
-6
lines changed- Section10Methods/LocalandGlobalVariables/src
1 file changed
+6
-6
lines changedLines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | 1 | | |
6 | 2 | | |
7 | 3 | | |
| |||
29 | 25 | | |
30 | 26 | | |
31 | 27 | | |
32 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
0 commit comments