0

What is the output of below code

public class StaticBasics{ private static int count; static{ System.out.println("static block"); System.out.println(count); main(null); } public static void main(String[] arhs) { System.out.println("main method"); } }

20th May 2020, 5:25 PM
Shabarish Kumar Elluru
Shabarish Kumar Elluru - avatar
4 Réponses
+ 3
You could have just run the code in the code playground BTW, class keyword is missing and identifier is missing for the count variable
20th May 2020, 5:30 PM
Мг. Кнап🌠
Мг. Кнап🌠 - avatar
+ 1
Just like Sami Khan mentioned, this would give you an output. public class StaticBasics{ private static int count; static{ System.out.println("static block"); System.out.println(count); main(null); } public static void main(String[] arhs) { System.out.println("main method"); } } Static blocks are executed at the time of class loading so they are run even before the main method is executed. You can run the code to see the output for yourself.
20th May 2020, 6:49 PM
Avinesh
Avinesh - avatar
0
No
20th May 2020, 5:32 PM
Shabarish Kumar Elluru
Shabarish Kumar Elluru - avatar
0
Read the code carefully
20th May 2020, 5:32 PM
Shabarish Kumar Elluru
Shabarish Kumar Elluru - avatar