Chapter3.java:74: cannot resolve symbol symbol : method method (java.lang.String) location: class Test test.method("0"); ^ Chapter3.java:81: cannot resolve symbol symbol : variable str location: class Test System.out.println(t.str);
1)i have no idea why this line1 is not compiling . please help me to correct the preceding errors?
2)what is the result of this program.i thought,this would print 0,0,0.Any ideas?
when t is a static reference, it refers to an instance of Chapter3. However, str is an instance variable that is not initialized by a constructor, so it is given its default value.
The reason you get a StackOverflowError when you make t an instance reference is that when a new instance of an object is created, its instance variable initializers are executed before the constructor is executed.
So by having the instance creation statement in the instance variable initializer, you basically have an infinite loop. Eventually the stack will be full.