Java: What is the difference between and ?

<init> is the (or one of the) constructor(s) for the instance, and non-static field initialization.

<clinit> are the static initialization blocks for the class, and static field initialization.

class X {

   static Log log = LogFactory.getLog(); // <clinit>

   private int x = 1;   // <init>

   X(){
      // <init>
   }

   static {
      // <clinit>
   }

}

Leave a Comment