Guided Notes
Methods
Defining methods, parameters and return values, overloading, scope, and recursion.
Defining methods
Slide 1 / 5A method is a named block of code you can call again and again:
static int square(int x) { return x * x; }
• static — belongs to the class (no object needed); objects come later. • int — the return type. Use void when nothing is returned. • square — the name, in camelCase. • (int x) — the parameters.
Call it: int result = square(5); // 25