Home TechnologyProgrammingJava Subscribe to RSS

Why Do We Use (main())function In Java? Why Not Static Block Function?

Answer Question

2 Answers - Sort by: Date | Rating

    Hello sir,Main is a static function only.How can the compiler know where to begin,if you dont specify main??
    0 0

    Nlgopi  

    answered 7 months ago

      Static blocks are executed in an undefined order, which is why a static block shouldn't refer to anything outside of its class.  If you were to use a static block rather than main(), other static blocks might not have executed yet and thus some class variables might be uninitialized.
      0 0
      Guest

      Guest  

      answered 7 months ago

        More

           
           

          Ask a Question via Twitter

          Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

          Blurtit Store

          Get T-shirts, hoodies, caps and more at the Blurtit store

          Blurtit International