Question #125074

What are parameters for? What is the difference between formal parameters and actual parameters? Give an example in Java code that illustrates formal parameters and actual parameters.

Expert's answer

Parameters are used to provide some external data for a method. A formal parameter is a variable in a function definition, while an actual parameter is an actual input at function call.


The next Java code illustrates formal and actual parameters:

class Main
{
    // The parameter in the function definition is a formal one
    public static void method(int formalParameter) { }

    public static void main(String[] args)
    {
        // The next variable that is passed to the method is an actual parameter
        int actualParameter = 5;
        method(actualParameter);
    }
}


See more here:

https://en.wikipedia.org/wiki/Parameter_(computer_programming)#Parameters_and_arguments

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS