Java | Constructors | Question 8
inside static block a = 4 inside constructor a = 11
(B) Compiler Error
(C) Run Time Error
inside static block a = 4 inside constructor a = 5
inside static block a = 10 inside constructor a = 11
Explanation: Static blocks are called before constructors. Therefore, on object creation of class Test, static block is called. So, static variable a = 4.
Then constructor Test() is called which assigns a = 10. Finally, function func() increments its value.
Quiz of this Question
Please comment below if you find anything wrong in the above post
My Personal Notes arrow_drop_up
Please Login to comment...