I know this is pointless: I just find it funny and I want to inquire more about the mechanics of what happens when you create a class that inherits itself, resulting in a stack
Remember that, since Inside
extends Outside
, it has an implicit call to super()
which is the constructor of Outside
(which in turn calls the constructor of Inside
) and so it goes around.
The code you posted is conceptually not different from the following program:
class A {
B b = new B();
}
class B extends A {
}
public class Test {
public static void main(String[] args) {
new A(); // Create an A...
// ... which creates a B
// ... which extends A thus implicitly creates an A
// ... which creates a B
// ...
}
}