[BAEL-5622] static vs instance initializer block (#12271)

* Deep copy vs Shallow copy Code commit

* Static and instance block

* Deep copy branch chanaged from master to other

* static vs instance block

* Update InstanceBlockExample.java

* Update StaticBlockExample.java

Co-authored-by: Lalit Rajput <lalit.rajput@globallogic.com>
Co-authored-by: paritoshsunny <sams.sunny.16@gmail.com>
This commit is contained in:
lalitrajput72 2022-07-30 16:09:02 +05:30 committed by GitHub
parent e9fdf78b77
commit ef758acef0
2 changed files with 39 additions and 0 deletions

View File

@ -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");
}
}

View File

@ -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");
}
}