----------------------------------------------------------------------
while i try to inialize the m1
code:
class Mixer {
Mixer m1 = new Mixer();
Mixer() {
}
Mixer(Mixer m) {
m1 = m;
}
public static void main(
String[] args) {
Mixer m2 = new Mixer();
Mixer m3 = new Mixer(m2);
m3.go();
Mixer m4 = m3.m1;
m4.go();
Mixer m5 = m2.m1;
m5.go();
}
void go() {
System.out.print("hi ");
}
}
it throws Java.lang.StackOverflowError why it throws StackOverFlowError ?
-----------------------------------------------------------------------------
When the program reaches line Mixer m2 = new Mixer(); an Mixer objext will be created. While creating that object the declaration Mixer m1 = new Mixer(); creates another object. So this looping happens continously which breaks 'stack'