World 5 of 26 · Beginner

🧩 Methods

13 Java concepts, each explained step by step with real code, a common trap and practice questions.

  1. Defining & calling methodsModifiers, return type, name, parameters, body.
  2. Return values & voidreturn ends the method; every path must return in non-void methods.
  3. Parameters vs argumentsFormal parameters receive copies of argument values.
  4. Java is always pass-by-valuePrimitives copy the value; references copy the reference (object can be mutated, variable cannot be re-pointed).
  5. Method overloadingSame name, different parameter lists; resolution order (exact, widening, boxing, varargs).
  6. VarargsType... args, must be last, received as an array.
  7. Static vs instance methodsstatic methods belong to the class and cannot use this.
  8. Local variables & scopeLocals live on the stack frame and die when the method returns.
  9. The call stackEach call pushes a frame; returning pops it.
  10. RecursionBase case + recursive case; tracing recursive calls.
  11. StackOverflowErrorMissing base case or too-deep recursion exhausts the stack.
  12. Method signatureName + parameter types; return type is not part of it.
  13. Pure functions & side effectsWhy methods that don't mutate state are easier to reason about.