What is the result of the following code execution?

public class Test {
    static { i = 5; }
    static int i = 6;

    public static void main(String[] args) {
        System.out.println(i);
    }
}
Explanation
Static initialization blocks and initialization of static variables are performed in the same order in which they are indicated in the class. Therefore, i = 5 command will be executed first and i = 6 after.

very good quesiton

2017 Jun 16, 12:01:15 PM

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes