A static initialization block begins with the static keyword and is encapsulated in braces. Here is an example,
static {
try {
charsInFile = 0;
FileReader in = new FileReader("TestStaticBlock.java");
while(in.read() != -1) {
charsInFile++;
}
} catch (Exception e){
}
System.out.println("Finished static initialization block: " + charsInFile);
}
No comments:
Post a Comment