Java: Calling Method

Last updated on:

Each time the method is invoked, the system creates an activation record( also called an activation frame) that stores parameters and variables for the method and places the activation record in area of memory known as call stack. A call stack is also known as an execution stack, runtime stack, or machine stack, and it is often shortened to just "the stack". When a method calls another method, the caller's activation record is kept intact, and a new activation record is created for the new method called. When a method finishes its work and returns to its caller, its activation record is removed from the call stack.


public class MaxNumber {
public static void main(String[] args) {
      
int i = 7;
int j = 3;
int k = 2;
System.out.println("The maximum of " + i + " and" + j + " is" + k);
      }

// Maximum number return method
public static int max(int number1, int number2) {
int result
if(number1 > number2) {
result = number1;
}
else{
result = number2;
}
return result
      }
}
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.