What is non static block in java?

What is non static block in java?

Any code written between a { and a } is a non-static block.

For example:
{
   // some code goes here
}
The non-static block code is executed when a new class is instantiated. It executes before the constructor’s execution. Apart from initialization, any other execution like calculation could be given in the non-static block, as a constructor is used for initializing purpose.
Explain how to sort the elements in HashMap - Java
The elements of HashMap can be sorted by using the static method Collections.sort()...
Difference between Checked and Unchecked exception
A checked exception throws a block of code and represented by the throws keyword...
Why Runnable interface is preferable than extending the Thread class - Java
Runnable interface is always preferred because, the class implementing it can implement as many interfaces as a developer can, and also extend another class...
Post your comment