The Initializer Block in Java Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 74 Likes Like Report In order to perform any operations while assigning values to an instance data member, an initializer block is used. In simpler terms, the initializer block is used to declare/initialize the common part of various constructors of a class. It runs every time whenever the object is created. The initializer block contains the code that is always executed whenever an instance is created and it runs each time when an object of the class is created. There are 3 areas where we can use the initializer blocks: ConstructorsMethodsBlocks Tip: If we want to execute some code once for all objects of a class then we will be using Static Block in Java Example 1: Java // Java Program to Illustrate Initializer Block // Class class Car { // Class member variable int speed; // Constructor Car() { // Print statement when constructor is called System.out.println("Speed of Car: " + speed); } // Block { speed = 60; } // Class member method public static void main(String[] args) { Car obj = new Car(); } } OutputSpeed of Car: 60 Example 2: Java // Java Program to Illustrate Initializer Block // Importing required classes import java.io.*; // Main class public class GFG { // Initializer block starts.. { // This code is executed before every constructor. System.out.println( "Common part of constructors invoked !!"); } // Initializer block ends // Constructor 1 // Default constructor public GFG() { // Print statement System.out.println("Default Constructor invoked"); } // Constructor 2 // Parameterized constructor public GFG(int x) { // Print statement System.out.println( "Parameterized constructor invoked"); } // Main driver method public static void main(String arr[]) { // Creating variables of class type GFG obj1, obj2; // Now these variables are // made to object and interpreted by compiler obj1 = new GFG(); obj2 = new GFG(0); } } OutputCommon part of constructors invoked !! Default Constructor invoked Common part of constructors invoked !! Parameterized constructor invoked Note: The contents of the initializer block are executed whenever any constructor is invoked (before the constructor's contents)The order of initialization constructors and initializer block doesn't matter, the initializer block is always executed before the constructor. For more details about the Instance Initialization in Java, refer to the article Instance Initialization Block (IIB) in Java Create Quiz Comment K kartik 74 Improve K kartik 74 Improve Article Tags : Java Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like