Java Program to Call an Instance Initializer Block Using the Anonymous Object

You are currently viewing Java Program to Call an Instance Initializer Block Using the Anonymous Object

Java program to call an Instance Initializer Block using the anonymous object

// Java program to call an Instance Initializer Block 
// using the anonymous object

class Sample {
  {
    System.out.println("Instance initializer block called");
  }

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

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

Output

Instance initializer block called
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