Answer to Question #125733 in Java | JSP | JSF for seth dacha

Question #125733
Discuss the concept of parameters. 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.
1
Expert's answer
2020-07-09T11:14:46-0400
/*
  Parameters are used to pass data to the method.
  This allows to call same method with different values of data.

  Actual parameters - variables or values passed to the method while calling.

  Formal parameters - variables declared in method signature (between parentheses).
*/


class Main {
  public static void main(String[] args) {
    int v = 1;

    // here, variable 'v' and value '2' are Actual parameters
    int result = sum(v, 2);

    System.out.println(result);
  }

  public static int sum(int a, int b) {
    // here, variables 'a' and 'b' are Formal parameters
    return a + b;
  }
}

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS