← Java Programming learning pathJava Programming · Module 4 of 10
Methods
Organise code into methods with parameters, return types and overloading.
📖 Key ideas
- A method: public static int add(int a, int b) { return a + b; }
- void methods return nothing.
- Java passes primitives by value and object references by value.
- Overloading: same name, different parameter lists.
- Recursion: a method calling itself with a base case.
💡 Real-life example: A method is a machine in a factory: same machine, any number of uses.
Return typeType of value a method sends back
voidReturns nothing
OverloadingSame name, different parameters
ParameterInput variable of a method