diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/initializerblock/instanceblock/InstanceBlockExample.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/initializerblock/instanceblock/InstanceBlockExample.java new file mode 100644 index 0000000000..c17fd8d3e6 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/initializerblock/instanceblock/InstanceBlockExample.java @@ -0,0 +1,22 @@ +package com.baeldung.initializerblock.instanceblock; + +public class InstanceBlockExample { + + { + System.out.println("Instance initializer block 1"); + } + + { + System.out.println("Instance initializer block 2"); + } + + public InstanceBlockExample() { + System.out.println("Class constructor"); + } + + public static void main(String[] args) { + InstanceBlockExample iib = new InstanceBlockExample(); + System.out.println("Main Method"); + } +} + diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/initializerblock/staticblock/StaticBlockExample.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/initializerblock/staticblock/StaticBlockExample.java new file mode 100644 index 0000000000..a409b6d7c8 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/initializerblock/staticblock/StaticBlockExample.java @@ -0,0 +1,17 @@ +package com.baeldung.initializerblock.staticblock; + +public class StaticBlockExample { + + static { + System.out.println("static block 1"); + } + + static { + System.out.println("static block 2"); + } + + public static void main(String[] args) { + System.out.println("Main Method"); + } +} +