ICSE Class 9 Computer Applications Question 5 of 10

Working with Methods — Question 5

Back to all questions
5
Question

Question 5

Explain the difference between actual and formal parameters with one example of each.

Answer

The parameters that appear in the method definition are called formal or dummy parameters whereas the parameters that appear in the method call are called actual parameters. Example:

public class FindSquareDemo {

    public int FindSquare(int x) {
        int result;
        result = x * x;
        return result;
    }

    public void MyFindSquare() {
        int num = 4;
        int myResult;
        myResult = FindSquare(num);
        System.out.println("Square of " + num + " is " + myResult);
    }
}

Here, variable x in the definition of FindSquare is formal parameter and variable num in the method call of FindSquare is actual parameter.