GCGrowCarrer

Methods

Locked

Lesson 8 of 60 · Syntax · Medium

Finish these first:Loops →Or pass the tests below to unlock it now.

1

The big idea

Methods declare return type, name, parameters. Java is pass-by-value (object references are copied).

Think of it like this: Think of syntax and expressions like labeled measuring cups in a kitchen: each cup holds a specific kind of ingredient, and operators combine them into a new measurement.
Key words (tap to learn):
2

Read the lesson

Methods declare return type, name, parameters. Java is pass-by-value (object references are copied). Overload by parameter list; varargs with T....

static int sum(int... xs) {
    int t = 0;
    for (int x : xs) t += x;
    return t;
}
3

Quick check

Before writing code: What should `Solution.add(1,2)` return when your implementation of Methods is working?

4

Your challenge

3 sample tests, 1 hidden

Write overloaded static int add(int a, int b) and static int add(int a, int b, int c).

Stuck? Get a hint (free)
More learning tools(compare languages, visual guide, related lessons)

Compare with another language

Similar to javascript.functions (88% overlap). Function signatures, return contracts, and lexical vs static scoping.

Visual walkthrough

A diagram, a step-by-step animation, and short captions for Methods.

Mastery0%