Q:

Java program to create multiple Instance Initializer Block

0

Java program to create multiple Instance Initializer Block

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will create multiple 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 create multiple Instance Initializer Block is given below. The given program is compiled and executed successfully.

// Java program to create multiple Instance 
// Initializer Block

class Sample {
  {
    System.out.println("IIB1 called");
  }

  {
    System.out.println("IIB2 called");
  }

  Sample() {
    System.out.println("Constuctor called");
  }

  {
    System.out.println("IIB3 called");
  }
}

public class Main {
  public static void main(String[] args) {
    Sample S = new Sample();
  }
}

Output:

IIB1 called
IIB2 called
IIB3 called
Constructor called

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to call an Instance Initializer Block... >>
<< Java program to implement instance initializer blo...