[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 <[email protected]> Co-authored-by: paritoshsunny <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
Lalit Rajput
paritoshsunny
parent
e9fdf78b77
commit
ef758acef0
+22
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user