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

3.1 Methods — organizing a program

Lesson

Breaking a program into methods

Instead of one long pile of statements, split a program into named methods and call them in order from main. This makes code easier to read and lets you reuse steps. The output follows the order of the calls.


Worked example

// hello() prints "Hello", bye() prints "Bye"
hello();
bye();

Called in this order, the program prints Hello then Bye.


▶ Try it: the methods hello() and bye() are defined for you. Run this, then swap the order of the two calls and re-run — the output order follows the call order.



hello() prints Hello and bye() prints Bye. What does bye(); hello(); print?


Type exactly what this program prints.

public class Main {

    static void line() {
        System.out.println("---");
    }

    public static void main(String[] args) {
        line();
        line();
    }
}

Sort each statement about methods.


True or false?