what is static block how its actually work in java program?

it is created when class loaded and program started from main function?????

  • Priyanka Kumari
  • Priyanka Kumari
  • |
  • 20 Mar
  • |
  • 213 Views
  • |
  • 7 Answers

text limit upto 4000

  • 1

    Static block is used for initializing the static variables.The static block gets executed when the class is loaded in the memory. We can have multiple static blocks in a class.The Static blocks will be executed in the same sequence in which they have been written into the program.

    • Voted By:
    • Rahul

  • 1

    Static block is used for initializing the static variables.This block gets executed when the class is loaded in the memory. A class can have multiple Static blocks, which will execute in the same sequence in which they have written into the program.

    • Voted By:
    • Rahul

  • 0

    In simple terms, a static block is a normal block of code enclosed in braces { } and preceded by the static keyword. Here is an example: 

    static { // code which is needed for initialization goes here }
    If you are continously stucking in the basic concepts and want to brush up your knowledge then you can join java training institute in Delhi


  • 0

    Static Block. Static block is used for initializing the static variables.This block gets executed when the class is loaded in the memory. A class can have multiple Static blocks, which will execute in the same sequence in which they have been written into the program


  • 0

    By using static block we can initialize the data member It is executed before main method


  • 0

    Static block is mostly used for changing the default values of static variables.This block executes when the class is loaded in the memory.


  • 0

    Java static block is the group of statements that gets executed when the class is loaded into memory by Java ClassLoader. It is used to initialize static variables of the class. Mostly it’s used to create static resources when class is loaded.


Did Not Get The Answer? 
Contact people of Talent-Core Java directly from here