Answers:1) Of course no error, since you are accessing t.myString inside t itself! Note that your main method is part of the MyThread class. Furthermore, Java's default access specification for member variables and methods is NOT private! The default specification allows access from any class in the same package. As your MyThread class is not in any package (effectively in the so-called "global" package), and I suppose so is your other test classes, myString is accessible.
2) The x in the first static scope cannot be accessed, because it is destroyed straightaway after it is declared! Note that static {...} structure is usually useful only in the global scope, i.e., outside any class. Basically, it provides static initialization routines to be executed before everything else (of course, there are still necessary initializations like class loading before this). Don't confuse the static code fragment with static member variable of a class.
are u saying that
any var(s) declared within static{} will not be reachable any more after the control flow gets out of that block?
pls correct me if i am wrong. 3x :D
pls correct me if i am wrong. 3x :D