| Author |
intiliazation blocks
|
Chetan Dodiya
Ranch Hand
Joined: Jun 27, 2008
Posts: 39
|
|
class Tarsier{ static String s="-"; public static void main(String [] args){ go(); System.out.println(s); } {go();} static{go();} static void go(){s+="s";} } the answer is "-ss" but why "-sss" why the {go();} is not executeg???
|
SCJP 1.5
|
 |
M Srilatha
Ranch Hand
Joined: Aug 27, 2008
Posts: 137
|
|
Please quote the source from where you got the question! {go();} is not executed because its a instance initialization block. In the main() method, no object of the class is created. So this block doesnt execute. Add Tarsier t = new Tarsier(); to the main() method. Then it will execute!
|
Thanks,<br />Srilatha M
|
 |
 |
|
|
subject: intiliazation blocks
|
|
|