Static Control Flow – 2

Video LInk :

Static Block
1. Static Blocks will be executed at the time of Class Loading hence at the time class loading if we want to perform any activity we have to define that inside a static block.
2. At the time of Java class loading the corresponding native library should be loaded hence we have to define this activity inside a static block.
3. After Loading every database driver class we have to register driver class with driver manager but inside database driver class there is a static block to perform this activity and we are not responsible to register explicitly
4. Within a class, we can declare any number of a static block but all this static block executed top to bottom.

*There are multiple ways to print statement without static block and the main method.
*From 1.7 version onwards main method is mandatory to start a programme execution. Hence, *from 1.7 versions onwards without writing the main method it is impossible to print some statement to the console.

Static Control Flow in Parent to Child relationship

Whenever we are executing child class the following sequence of event will be executed automatically as the static control flow
1. Identification of static member from parent to child.
2. Execution of static variable assignment and static blocks from parent to child.
3. Execution of only child class main method.

Whenever we are loading child automatically parent class will be loaded but whenever we are parent class child class won’t be loaded [because parent class members by default available to the child class whereas child class members by default won’t available to the parent].

Leave a Reply

Your email address will not be published. Required fields are marked *