Task 5 of 7 · 0 solved · 7 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

3.2 Methods — arguments vs parameters

Lesson

Two words: parameter and argument

The named slot inside the method header (like name) is a parameter. The actual value you pass in the call (like "Ada") is an argument. An argument can be a literal, a variable, or an expression — whatever produces a value of the right type.


Worked example

void greet(String name) {          // name is the parameter
    System.out.println("Hello, " + name + "!");
}

String who = "Sam";
greet(who);        // argument is a variable
greet("direct");   // argument is a literal

▶ Try it: run this — the first call passes a variable as the argument, the second passes a literal. Change the variable's value and re-run.



The named slot inside the method (like name) is the ___; the value you pass in a call (like "Ada") is the ___.


Which of these can be used as an argument?


Sort each item as a parameter (in the method header) or an argument (in a call).


True or false?


Type exactly what this program prints.

public class Main {
    static void shout(String w) {
        System.out.println(w + "!");
    }
    public static void main(String[] args) {
        String word = "go";
        shout(word);
        shout("stop");
    }
}