Methods
LockedLesson 8 of 60 · Syntax · Medium
Mastery0% of 85%
Up next: Variables and Primitive Types (~7 min) →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
3 sample tests, 1 hiddenYour challenge
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%
Learn this first
- LoopsNot yet