Q:

Java program to implement instance initializer block

0

Java program to implement 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 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

 

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

total answers (1)

Java program to create multiple Instance Initializ... >>