Java-Execution of Static Block and Constructor

Execution of Static Block and Constructor The static blocks execute when the class is loaded, and the non-static blocks(Constructor, methods) execute when each object is created. Program Program Source class Data { static { System.out.println(“Static block”); } Data() { System.out.println(“Constructor”); } } public class Javaapp { public static void main(String[] args) { Data obj = … Read more…

Java-Static Block

Static Block Sometimes, we may wish to assign initialize values to a set of static variables when a class is loaded into memory. In such situations, we shall define and use a block of statements in the form of a static initialization block. Static block is a special type of blocks are blocks defined within … Read more…