Java Static Initializer Block

  • + 1 comment

    can some body explain the role of flag in the above example ?? why do we need a flag , what does it do?i tried the code without the flag but it dosent work!please help

    • + 1 comment

      see the main method There it's written that print B*H (if and only if flag ==true) And since we know that static block gets initialised as soon a s the class is loaded, So, as soon as the class is loaded and the values of B and H are loaded it's checked that is flag still equal to true

      I HOPE THAT YOU GOT IT NOW But still if you have any doubt feel free to ask

      • + 0 comments

        yaa ..thank you very much brother ..