Download presentation
Presentation is loading. Please wait.
1
Unit-1 Introduction to Java
Java methods
2
A method is a programming construct used for grouping the statements together to build function.
There are two ways by which the method is handdled 1.Defining a method 2.Calling a Method
3
Call Stacks Each time a method is invoked, the system stores parameters and variables in an area of memory, known as a stack, which stores elements in last-in first-out fashion. When a method calls another method, the caller's stack space is kept intact, and new space is created to handle the new method call. When a method finishes its work and returns to its caller, its associated space is released. The variables defined in the main method are i, j, and k. The variables defined in the max method are num1, num2, and result. The variables num1 and num2 are defined in the method signature and are parameters of the method. Their values are passed through method invocation. Figure 5.4 illustrates the variables in the stack.
4
Void Method The method has a return type void when it returns nothing.
Such method is defined using keyword void. There is no return statement for such method.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.