Answer to Question #147398 in Java | JSP | JSF for Nompumelelo

Question #147398

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-11-29T23:47:51-0500

Parameters are values that could be passed to methods. Methods process passed parameters in some ways. Parameters are used to modify methods executions results.


Inside method declaration and body formal parameters are used to represent passed parameters values. Values than were actually passed to method are called actual parameters.

Example - here "a" and "b" are formal parameters, x and y, containing values 6 and 7 respectively, are actual parameters:

public static int sum(int a, int b) {
  return a + b;
}

public static void main(String[]) {
  int x = 6;
  int y = 7;
  System.out.println(sum(x,y);
}

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