This flow shows how the main method calls another method, executes it, and then returns to continue.
code_blocksExecution Sample
Java
publicclass Test {
publicstaticvoid main(String[] args) {
int result = add(3, 4);
System.out.println(result);
}
publicstaticint add(int a, int b) {
return a + b;
}
}
This code calls the add method with 3 and 4, then prints the sum.
data_tableExecution Table
Step
Action
Method
Parameters
Return Value
Output
1
Start main method
main
args
N/A
N/A
2
Call add method
add
a=3, b=4
N/A
N/A
3
Execute add method body
add
a=3, b=4
7
N/A
4
Return to main method
main
N/A
7
N/A
5
Print result
main
N/A
N/A
7
6
End program
main
N/A
N/A
N/A
💡 Program ends after printing the result.
search_insightsVariable Tracker
Variable
Start
After Step 2
After Step 3
After Step 5
Final
result
undefined
undefined
7
7
7
a
N/A
3
3
N/A
N/A
b
N/A
4
4
N/A
N/A
keyKey Moments - 3 Insights
▶Why does the program jump to the add method when it is called?
▶What happens to variables a and b after add finishes?
▶Why does main store the return value from add in result?
psychologyVisual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of 'result' after Step 3?
Aundefined
B3
C7
D4
photo_cameraConcept Snapshot
Method calling in Java:
- Use methodName(arguments) to call a method.
- Program jumps to method, runs code, then returns.
- Returned value can be stored in a variable.
- Parameters are local to the method.
- After return, program continues where it left off.
contractFull Transcript
This example shows how Java calls a method named add from main. The main method starts and calls add with 3 and 4. The program jumps to add, runs its code to add the two numbers, and returns 7. Main receives 7 and stores it in result. Then main prints 7 and ends. Variables a and b exist only inside add. This flow helps understand how methods work step-by-step.