java - Commands in anonymous blocks inside a class of any use -
if seen question here: instance initializer , *this* keyword
and ask myself this:
public class main { public static void main(string args[]) { new main(); } { system.out.println(x); } //error here int x=1; }
of (even theoritical) use? mean part:
{ system.out.println(x); } //error here
as far can anonymous i'd have no idea how execute manually, doesn't seem executed automatically not part of function or whatsoever. sorry if questions answered, ones found targeted {} restrict variable scope in case not think of way scope or make run.
it's instance initialization block. whenever create instance of class, executed before body of constructor use.
therefore way execute manually
creating instance of class in block appears (or sub-class of class).
Comments
Post a Comment