Java – Does this qualify for recursion?

Does this qualify for recursion?… here is a solution to the problem.

Does this qualify for recursion?

I know that the function that calls itself is recursive. But is it recursive for an object to create an object of its own type? Also, I have no intention of using this code because it obviously causes problems and I’m only interested in whether it meets the recursion criteria.

class Cell 
{
    Cell()
    {
        Cell c = new Cell();
    }
} 

Solution

Indeed it is. The Cell constructor will be called by itself, assuming that some calling code triggers the construction of the Cell instance.

Unless you somehow block recursion (there may be a maximum instance limit), your program will eventually crash.

Related Problems and Solutions