- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java static block
static keyword can be used to create a block to be used to initialize static variables.
This static block executes when classloader loads the class. A static block is invoked before main() method. You can verify the same using.
Example
public class Tester { static { System.out.println("In static block"); } public static void main(String[] arguments) { System.out.println("In main"); } }
- Related Articles
- A static initialization block in Java
- A non-static initialization block in Java
- How to execute a static block without main method in Java?
- What are the restrictions imposed on a static method or a static block of code in java?
- \nHow to throw an exception from a static block in Java? \n
- Sequence of execution of, instance method, static block and constructor in java?
- Can we throw an Unchecked Exception from a static block in java?
- Why interfaces don't have static initialization block when it can have static methods alone in java?
- What are the differences between a static block and a constructor in Java?
- Why we can't initialize static final variable in try/catch block in java?
- Java static keyword
- Java static variable
- Java static method
- Static variables in Java
- Static class in Java

Advertisements