I have two questions:
Q1)class
Fruit {
static Fruit f = new Fruit();//*I
Fruit g; //*II
Fruit h = new Fruit();//*III
}
class Tomato
{
public static void main(
String args[])
{
Fruit f = new Fruit();//*IV
}
}
In 1) if i include *III and *IV lines an error comes
like this an errror comes like this:
Exception in
thread "main" java.lang.StackOverFlowError
at Fruit.<init>(Compiled Code)
at Fruit.<init>(Compiled Code)
at Fruit.<init>(Compiled Code)
at Fruit.<clinit>(Tomato.java:3)
Why so and what this means?
---------------------------
In 1) if I exclude *III and *IV no errors.
In 1) if I exclude *IV and include *I,*II,*III
no such errors.How?
-------------------------------------------------------------------------
-----------------------------------------------------------------------
Q2)At what time static methods get executed-compile
time or at runtime (with initialization)?