Function
Method Declaration:
access_modifier return_type method_name(parameter_list) {
// Method body
// Code to be executed
return value; // Return statement (if the method returns a value)
}Example of a Method:
public class Example {
// Method that takes two integers as parameters and returns their sum
public int addNumbers(int a, int b) {
int sum = a + b;
return sum;
}
public static void main(String[] args) {
Example example = new Example();
int result = example.addNumbers(5, 10);
System.out.println("Sum: " + result);
}
}Last updated