-1

I saw this sample code at Oracle Certification website and someone here can explain me the concept of static {} ?

public class Sequence {

Sequence() {
    System.out.print("c ");
}

{
    System.out.print("y ");
}

public static void main(String[] args) {
    new Sequence().go();
}

void go() {
    System.out.print("g ");
}

static {
    System.out.print("* ");
}

}
Danilo
  • 41
  • 7
  • the `static` block will be the first block called when the class is compiled and ran. See the following : http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.7 – Tom C Mar 24 '16 at 16:50
  • Thank you so much! – Danilo Mar 24 '16 at 16:59

1 Answers1

0

one with static keyword static initialization block not a method ,it runs when class in loaded.

the other {} without static is a initialization block it runs after super() call is made by constructor

Ramanlfc
  • 8,283
  • 1
  • 18
  • 24