Recursion in Java in Java

🟢 Beginner Level | Java Core Syntax

📖 Definition

Recursion occurs when a method invokes itself. Every recursive method requires a well-defined base case to terminate execution and prevent StackOverflowError.

âš¡ Code Example

public static int factorial(int n) {
    if (n <= 1) return 1; // Base case
    return n * factorial(n - 1);
}

🧭 Navigation

← 03. Pass-by-Value & Varargs | Module Hub | Module Hub →