Hi paramesh
Code 1:
class stack
{
stack ss = new stack();
public static void main(
String[] as)
{
new stack();
}
}
This normally throws stack overflow because when we create a object, JVM allocates space for reference ss and try to create a new space for its object, which it tends creates new space for its reference and try to assign its object for it...
so this way it going end up with a stack overflow error
In the code 2(part of your code)
static
{
int x;
outer o=new outer();
o.outermethod();
}
whenever a variable is declared in a block its scope ends when block ends
In the code 3(Part of your code)
public void innermethod()
{
outer oo=new outer(); //1
oo.outermethod(); //2
oo.y=5;//whats the difference between //3
System.out.println(outer.this.y);//these two lines // 4
System.out.println(oo.y); System.out.println("innerrmethod");
}
5 is instialized to value oo u created in line 2.
But outer.this.y refers to currently running object of outer class so it prints 2
4
Very well we can use this in constructor