Commit 796dd6c
committed
Add example demonstrating default Object toString() behavior in Java
Created a `student` class with fields `studentID` and `name`, along with a constructor to initialize them.
In the `toStringMethod` class, instantiated two `student` objects and printed them using `toString()`.
Logic: Since the `toString()` method is not overridden, the output shows the default implementation from `Object` class — which prints the class name followed by the object's hash code in hexadecimal. Comments in the code explain how `Object.toString()` works internally and what it returns if not overridden.
Prepared the code to allow comparison by optionally uncommenting the custom `toString()` method.
Signed-off-by: Somesh diwan <[email protected]>1 parent e186f41 commit 796dd6c
File tree
1 file changed
+6
-8
lines changed- Section6StringClassPrinting/Engineering Digest ED/src
1 file changed
+6
-8
lines changedLines changed: 6 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | | - | |
7 | | - | |
| 5 | + | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
| 9 | + | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
36 | 34 | | |
37 | 35 | | |
38 | 36 | | |
| |||
0 commit comments