← Java Programming learning path
Java Programming · Module 4 of 10

Methods

Organise code into methods with parameters, return types and overloading.

📖 Key ideas

  1. A method: public static int add(int a, int b) { return a + b; }
  2. void methods return nothing.
  3. Java passes primitives by value and object references by value.
  4. Overloading: same name, different parameter lists.
  5. 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