Java Program printing infinitely before crashing

Your DrowRanger method is calling itself infinitely. This is almost always the cause of a StackOverflowException.

This line:

return DrowRanger(); 

Calls the DrowRanger method, but since you’re inside the DrowRanger method it just keeps calling itself infinitely. I think you meant to return the local object:

return DrowRanger;

In general, it is a bad idea to give methods and objects the same name. Also, it is java convention always start method and variable/field names with a lowercase letter.

The output you’re seeing is how java prints objects that have not overridden the toString() method. See this post for an explanation of how the toString() method works.

Leave a Comment