Notes
In Apex, the return
keyword is used to exit a method and send a value back to the calling code. It is followed by an expression representing the value to be returned. Methods can be declared with a specific return type, and the returned value must match that type. For void methods, the return
statement is used to exit the method without returning a value. Conditional returns and early exits are common uses of the return
statement for effective program control.
public class MathOperations {
public static Integer addNumbers(Integer a, Integer b) {
Integer sum = a + b;
return sum;
}
}
Call the Method
Integer result = MathOperations.addNumbers(5, 8);
System.debug('Sum: ' + result);
Output: Sum: 13
Video
Video does not exists.