32 Initialization Blocks

Merhaba Arkadaslar,
Bu yazimda Java’da bulunan initialization(ilk kullanima hazirlama) blocks konusundan bahsedecegim. Java da 2 turlu initialization block vardir.

  • static initialization block
  • instance initialization block

Bir sinif yuklediginde ilk olarak ve sadece 1 kez static initialization block calisir.st
Instance olusturulda her defasinda instance initialization block calisir.

Basit bir ornek yapalim ;

public class InititialTest {

	static {
		System.out.println("Static Initialization Block");
	}

	{
		System.out.println("Instance Initialization Block");
	}

	public static void main(String[] args) {

		System.out.println("Main -1 ");
		InititialTest initial = new InititialTest();
		InititialTest initial2 = new InititialTest();

	}

}

Continue reading 32 Initialization Blocks