In this program, we will implement an Instance Initializer Block in a class. The IIB (Instance Initializer Block) is called when an object is getting created.
Program/Source Code:
The source code to implement the instance initializer block is given below. The given program is compiled and executed successfully.
// Java program to implement instance initializer block
class Sample {
{
System.out.println("Instance initializer block called");
}
Sample() {
System.out.println("Constructor called");
}
}
public class Main {
public static void main(String[] args) {
Sample S = new Sample();
}
}
Output:
Instance initializer block called
Constructor called
In this program, we will implement an Instance Initializer Block in a class. The IIB (Instance Initializer Block) is called when an object is getting created.
Program/Source Code:
The source code to implement the instance initializer block is given below. The given program is compiled and executed successfully.
Output: