Commit 9b13f8e
committed
feat: Add FunctionsCC2 class with calculateSum returning result
WHAT the code does:
- Defines a `FunctionsCC2` class with a static method `calculateSum(int num1, int num2)`.
- Unlike the previous version, this method **returns** the sum instead of printing it.
- `main()` calls `calculateSum(3, 4)` and prints the returned result → `7`.
WHY this matters:
- Demonstrates the difference between methods that **return values** vs those that only print.
- Returning values increases **reusability** since the result can be stored, reused, or combined with other logic.
- Highlights better design for utility methods.
HOW it works:
1. `calculateSum(3, 4)` computes `7`.
2. Method returns `7` to the caller.
3. `main()` prints the returned value.
Tips & gotchas:
- Returning instead of printing allows combining results in further calculations.
- If used in multiple places, avoids redundant printing.
- Works for integers only — overloading or using generics could extend flexibility.
- For larger ranges or performance-critical cases, ensure integer overflow is considered.
Use-cases:
- Educational example for **methods with return values**.
- Building block for calculator applications.
- Utility function for number-crunching programs.
- Serves as a comparison against `FunctionsCC` which prints directly.
Short key: class-functions cc2-calculate sum-return.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 7990091 commit 9b13f8e
1 file changed
+2
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
| 8 | + | |
0 commit comments