美文网首页
Why java main method is static?

Why java main method is static?

作者: 落魄平生 | 来源:发表于2017-06-29 12:06 被阅读0次

This is neccesary because main() is called by the JVM before any objects are made. Since it is static it can be directly invoked via the class. Similarly, we use static sometime for user defined methods so that we need not to make objects. void indicates that the main() method being declared does not return a value.

Q)** why java main method is static?**
Ans) because object is not required to call static method if it were non-static method, jvm create object first then call main() method that will lead the problem of extra memory allocation.

相关文章

网友评论

      本文标题:Why java main method is static?

      本文链接:https://www.haomeiwen.com/subject/dbsmcxtx.html