0

What is static block?

What is static block in Java, on which condition it is used in real world. Please provide some of real world example

7th Oct 2021, 2:26 AM
Gul Mohammed
Gul Mohammed - avatar
3 Réponses
+ 3
we can use the static keyword with a block of code that is known as a static block. A static block can have several instructions that always run when a class is loaded into memory. It is also known as java static initializer block because we can initialize the static variables in the static block at runtime. A class can have any number of static blocks, The JVM executes them in sequence in which they have written. The static block in a program always executed first before any static method, non-static method, main method, or even instance block.
22nd May 2022, 3:16 AM
😇🌟SWATI🌟😇
😇🌟SWATI🌟😇 - avatar
+ 1
Specify a language and some more details about your question Edit: The question is edited
7th Oct 2021, 2:32 AM
Rishi
Rishi - avatar
+ 1
If you define a static keyword you can access that without making its object like public static void main in java, we can use this class without making its object
7th Oct 2021, 5:05 AM
Aryan Yadav
Aryan Yadav - avatar