Commit 50e66a1
committed
feat: Add FunctionsCC5 class with calculateSum and return type example
WHAT the code does:
- Defines a `FunctionsCC5` class with a static method `calculateSum(int num1, int num2)`.
- `calculateSum()` computes and **returns** the sum of two integers.
- `main()` calls the method with arguments `(3, 4)` and prints the result → `7`.
WHY this matters:
- Demonstrates the importance of **return types** in Java methods.
- Shows that return types can be changed (e.g., `int`, `double`, `String`) depending on desired output.
- Reinforces declaring return types explicitly for type safety.
HOW it works:
1. `calculateSum(3, 4)` → computes `3 + 4 = 7`.
2. Returns `7` to the caller.
3. `main()` prints the result.
Tips & gotchas:
- Return type must match the actual returned value → otherwise, compile-time error.
- Method only handles two integers → could extend with overloading or varargs for flexibility.
- If changed to `double`, division or floating-point sums could be supported.
- Comments highlight importance of specifying return type correctly.
Use-cases:
- Educational example for **methods with return values and type declarations**.
- Base for calculator functions.
- Useful in teaching type safety and compiler enforcement in Java.
- Can be extended for sums involving arrays or multiple numbers.
Short key: class-functions cc5-return type-example.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 0ad057f commit 50e66a1
1 file changed
+4
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | 1 | | |
5 | | - | |
6 | | - | |
| 2 | + | |
| 3 | + | |
7 | 4 | | |
| 5 | + | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
12 | | - | |
| 10 | + | |
0 commit comments