• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Test Case Examples
  • Interview Questions
  • Interview Questions Asked
  • Java
  • Java Program
  • Selenium
  • Selenium Programs
  • Manual Testing
  • Difference
  • Tools
  • SQL
  • Contact Us
  • Search
SoftwareTestingo » Difference » Instance Initialization blocks Vs Static Initialization blocks In Java Example Tutorial

Instance Initialization blocks Vs Static Initialization blocks In Java Example Tutorial

Last Updated on: April 14, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • Static Initialization Blocks vs Instance Initialization blocks In Java:

Static Initialization Blocks vs Instance Initialization blocks In Java:

In this article, we will list the difference between Static Initialization blocks and Instance Initialization blocks in Java. Before moving ahead with the differences, read the detailed concepts about these concepts in detail in the following articles

  • Initialization blocks (Static and Instance blocks)
  • The execution order of constructor and Initialization blocks

Let us detail out the difference between Static Initialization blocks vs Instance Initialization blocks in tabular form below.

Static Initialization blocks
Instance Initialization blocks
This is also referred to as “static blocks” or “static initializer” This is also referred to as “instance blocks” or “instance initializer”
Static blocks are a bundle of valid Java statements within {curly braces} prefixed with the static keyword Instance blocks are a bundle of valid Java statements within {curly braces}
Note: Just opening and closing curly braces and there is no keyword
Syntax:

static
{
// bundle of Java logics
}

Syntax:

{
// bundle of Java logics
}

Static blocks are executed, at the time of class loading Instance blocks are executed, every time object is created using the new keyword
Executed only once, at the time class loading Executed every time the instance is created
Static blocks can be used to initialize static data members and invoke static methods only Instance blocks can be used to initialize instance data members and invoke instance methods
Since static blocks belong to a class, this and super keywords are not allowed this keyword is used to access instance data members in instance blocks
Order of execution: Static blocks are always executed first comparing with instance blocks, at the time class loading Order of execution: Instance blocks are executed after static blocks, as instance blocks executed only when an object created
Read Also: java interview questions

If you like SoftwareTestingo and would like to contribute something to this community, then you can also write an article using our Contact us page or mail your article to admin@softwaretestingo.com. So that we can review your article and that also appears on the SoftwareTestingo.com main page and help other Testers.

Please Improve this article, if you find anything incorrect by commenting on the comment box and we are happy to work on the article to maintain the accuracy and improvement.

    Filed Under: Difference

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Copyright © 2023 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers