A block that is created using the static keyword is called static block. The static block is used to initialize the static members of the class. Static block is not member of the class, and it cannot have return statement.
The static block can use only other static members of the class, it cannot access instance members of the class.
Static block is executed only once before the execution of the main method and before constructor of the class.
A class can have any number of static blocks and they are executed in the order, in which they are defined.
this keyword and super keyword cannot be used in the static block.
In java 1.6 and earlier the static block was executed even if class did not have main method, but after java 1.6 the static block is executed only if our class has the main method. The following example demonstrates the static block.
public class DemoStaticBlock
{ static
{ System.out.println("This is the static block1");//Will be executed first
}
public static void main(String[]args)
{ System.out.println("Inside the main function");//will be executed at last
}
}
#java #tarunsir #staticblock #coding
Sur cette page du site, vous pouvez voir la vidéo en ligne static block in java in hindi durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Tarun Sir 09 août 2021, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 225 fois et il a aimé 14 téléspectateurs. Bon visionnage!