[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:
parent
e9fdf78b77
commit
ef758acef0
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue