+ 1
In d below program the Output will come as 2 3 1 100 how it vl come can anyone explain? how d sop Statement work here?
class A { static int i; static { i = 100; System.out.println(1); } static void staticMethod() { System.out.println(i); System.out.println(2); } } public class B { static { System.out.println(3); } public static void main(String[] args) { System.out.println(4); System.out.println(A.i); A.staticMethod(); } }
7 Respostas
+ 2
But in my computer the answer is
3
4
1
100
100
2
+ 1
dude d question is r8 it was given as assignment in class
+ 1
i checked it bro it gave d output as i hv mentioned in question!!
+ 1
sorry man no idea how it's working
+ 1
when you run the program it looks main method.so firstly creating B class and loading static content
and printing 3,then program running main method ,in first println it prints 4 and second println creating A class firstly and loading static content in bracles and turning back println method and gets A.i value and printing it.
After these program call A.staticMethod .
0
Dude question is wrong or not fully written. Pls write full ques or explain understandable.
0
why don't u run it and check to find out