What is a formal parameter, in Java?

前端 未结 3 1360

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,

相关标签:
3条回答
  • 2021-01-04 10:22

    Well, coming to Java or any language these definitions always hold true:

    • caller — the function is invoking the function call.

    • callee — the function that is invoked by the caller.

    An argument term technically in programming refers to the data that is passed by caller to the callee.

    And a parameter term technically refers to the type of data being passed more specifically to an identifier which identifies the type of data. So a parameter more or less refers to the identifier that identifies a particular type. Coming further, a formal parameter is the identifier used in the callee's method signature.

    And an actual parameter is the identifier used by the caller when invoking the call.

    Since you know that we can even pass the arguments (i.e. data) in the call to the callee directly, actual parameters are not compulsory and hence directly data can be passed whereas formal parameters are always compulsory.

    0 讨论(0)
  • 2021-01-04 10:24

    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(...));
    
    0 讨论(0)
  • 2021-01-04 10:36

    In Java and in C++ the formal parameter is specified in the signature of the method:

    public void callIt(String a)
    

    callIt has a single formal parameter that is a String. At run-time we talk about actual parameters (or arguments), the :

    callIt("Hello, World");
    

    "Hello, World" String is an actual parameter, String a is a formal parameter.

    From the Wikipedia entry for parameter:

    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.

    0 讨论(0)
提交回复
热议问题