Caused by: java.lang.StackOverflowError code example

Example 1: stackoverflow error

It usually happens when the stack pointer exceeds the stack bound. Usually due to deep infinite recursions

Example 2: java.lang.StackOverflowError

public class Vehicle {
    public void accelerate(float acceleration, float maxVelocity) {
        // set the acceleration
    }
}

public class SpaceShip extends Vehicle {
    @Override
    public void accelerate(float acceleration, float maxVelocity) {
        // update the flux capacitor and call super.accelerate
        // oops meant to call super.accelerate(acceleration, maxVelocity);
        // but accidentally wrote this instead. A StackOverflow is in our future.
        this.accelerate(acceleration, maxVelocity); 
    }
}

Tags:

Java Example