Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a formal parameter, in Java?

I'm currently working on java legacy code and I encounter with a class that represent a formal parameter but I don't know why is that. I read about C++ Formal Parameters, but it confused me because in C++ it is the same as the argument (I'm in doubt about this affirmation) and in my legacy code it is a class, that has only a private int member that store a number (with their set & get methods) but honestly, I didn't find the why of that declaration.

like image 967
PlainOldProgrammer Avatar asked Dec 15 '14 22:12

PlainOldProgrammer


People also ask

What is formal parameter?

A formal parameter is a variable that you specify when you determine the subroutine or function. These parameters define the list of possible variables, their positions, and their data types.

What is a formal in Java?

The term parameter (sometimes called formal parameter) is often used to refer to the variable as found in the function definition, and: argument (sometimes called actual parameter) refers to the actual input passed.

What is formal and actual parameter?

Formal parameters are always variables, while actual parameters do not have to be variables. Actual Parameter. • Parameter Written in Function Call is Called “Actual Parameter”.

What is an example of a parameter in Java?

When a parameter is passed to the method, it is called an argument. So, from the example above: fname is a parameter, while Liam , Jenny and Anja are arguments.


1 Answers

Not disagreeing with Elliot Frisch at all, but I can say it more simply:

The variable w is a "formal parameter" in the following function definition:

void foobar(Widget w) {
    ...
}

The value returned by nextWidget(...) is the "actual parameter" when you write the following function call:

foobar(nextWidget(...));
like image 123
Solomon Slow Avatar answered Sep 27 '22 18:09

Solomon Slow