Function Flashcards
Define function
A program module used at different instances in a program to perform a specific task
Advantages of a method
Reuses a segment of operations when called upon
Divides a complex task into smaller methods
Occupies less memory
Define a method
< Access specifier > < return type > < method name > (Parameter list)
Private access specifier
Member of only that class can access function
Public Access Specifier
Function can be accessed by external class functions
Protected Access Specifier
Inherited members can access the protected functions
Features of Return statement
→ At the end of a method
can return only I variable
only one return statement can be used.
No statement is executed after return
Define “Invoking a method”
Process of using a method in a program
Formal parameters
Arguments that are passed to the methods. They receive values from the Caller method.
Actual parameters
Values actually passed to the method during its call from the main () functions
Ways of defining a function
Value, outcome
Value, no outcome
No value, outcome
No value, no outcome
What are the different ways of passing values to a function
Pass by value
Pass by reference
Pass by value
Passing a copy of actual parameters to the formal parameters. Any change made in the formals does not reflect on the actuals.
Pass by Reference
Passing the reference/ address of an actual parameter to a formal parameter. Both share the same memory location.
Pure Function (AKA accessor method)
A function which returns a value to its caller module without changing the state (value) of an object.