Commit 76268d2
committed
feat: Add Employee class with encapsulation and overridden toString() method
- Implemented a basic `Employee` class with two private instance variables: `id` and `name`
- Provided public getter and setter methods for both fields, ensuring proper encapsulation
- Overrode the `toString()` method from `Object` class to return a meaningful string representation of an Employee object (`"id name"`)
- Demonstrated usage in the `main` method by:
- Creating an `Employee` object
- Setting values using setter methods
- Printing the object reference, which internally invokes the overridden `toString()` method
This commit highlights how `toString()` can be customized to improve object representation for debugging, logging, or output readability.
Signed-off-by: Somesh diwan <[email protected]>1 parent 58909fd commit 76268d2
File tree
1 file changed
+3
-3
lines changed- Section6StringClassPrinting/Engineering Digest ED/src
1 file changed
+3
-3
lines changedLines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
| 28 | + | |
30 | 29 | | |
31 | 30 | | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
0 commit comments