Method Basics
Parameters and Arguments
Method Structure & Syntax
Local Variables & Scope
Return Values
100

Write a correct void method named sayHello that prints “Hello, world!”

public static void sayHello() {
    System.out.println("Hello, world!");
}
100

How many parameters are allowed in a method?

Essentially, as many as you want.

100

What symbol is used to enclose a method body?

curly brackets { } 

100

What is a local variable?

A variable declared inside a method

100

What word is used at the end of some methods that sends a value back to the statement that called the method

return

200

Is this a method header or method call?

calcTotal();

Method call

200

What happens when a double is passed into a method expecting an int?

It causes an error because Java cannot narrow automatically

200

What is wrong with this method?

public int add(int a, int b) {

    System.out.println(a + b);

}

It is missing a return statement (it says int but doesn’t return a value).

200

Where can a local variable be used?

Only inside the method where it is declared.

200

What does the keyword void mean in a method?

The method does not return a value

300

Name the following parts of the method header:

public static double hey(int thing)

public → access modifier

static → thing you need

double → return type 

hey → method name

(int thing) → parameter

    int = parameter data type

    thing = parameter variable name

300

What's wrong with this method call?

displayValue(int x);

You do not include the data type in a method call

300

What is wrong with this method header?

public static calcTotal(int a, int b)

Missing return type

300

Why can two methods use local variables with the same name?

Because each method has its own separate scope.

300

What is my daughter's name?

Hayden Jo Curtis

400

What is the purpose of writing methods in a program? List two advantages of using methods.

Code reuse - You can write a method once and call it multiple times instead of rewriting the same code.

Easier to manage and debug (modularity) - Breaking a program into smaller parts makes it easier to read, test, and fix problems.

400

What is the difference between parameter and argument?

A parameter is a variable in the method definition that receives a value, while an argument is the actual value that is passed into the method when it is called.

400

What's wrong with this method:
public static int nums() {

    return 10.5

}

return statement doesn't match return type

400

What's wrong with this code:

public static void main(String[] args) {

     System.out.println(x);

}

public static int mystery(int n) {

    int x = n*n;

    return x;

}

x is not defined in main


400

Which method is a return type method, and which is a void method? Explain

print("Mrs. Schullo);

System.out.println(average(a, b));


print() → Void method

average() → Value-returning method

500

What planet is known as the “Red Planet”?

Mars

500
True or false: Parameters have to be of the same type.

False

500

What is the difference between correlation and causation?

Correlation means two variables are related or change together; causation means one directly causes the other.

500

How can you become a millionaire by the time you retire?

Contribute to your 403b or 401k early!!!!!

500

Why do we have seasons on Earth?

Because Earth is tilted on its axis, causing different parts of Earth to receive varying amounts of sunlight throughout the year as it orbits the Sun