• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static block or initialisation block

 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static block or initialisation block.. which of these first executes in a program..???
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
static intializer block executes when a class is intialized. instance intializer block is executed when a class is instantiated i.e. an object of a class is created. As you must know a class is loaded when the JVM starts. so static intializer block is executed when the JVM starts. But instance intializers execute when an object of a class is created. If no object of a class is created then the instance initializer block will never be executed.
 
venkatesh badrinathan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you AnkitJi Garg.. you are really great
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic