Java Program to Implement Instance Initializer Block With Superclass

You are currently viewing Java Program to Implement Instance Initializer Block With Superclass

Java program to implement instance initializer block with superclass

// Java program to implement instance initializer block 
// with superclass

class A {
  // Instance Initializer Block
  {
    System.out.println("A: IIB Called");
  }

  A() {
    System.out.println("A: Constructor Called");
  }
}

class B extends A {
  // Instance Initializer Block
  {
    System.out.println("B: IIB Called");
  }

  B() {
    super();
    System.out.println("B: Constructor Called");
  }
}

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

Output

A: IIB Called
A: Constructor Called
B: IIB Called
B: Constructor Called

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply