Why main() method is always static in Class ?

The main() method is static because the JVM needs a single entry point to execute the program without creating an instance of the class.

If main() is not static, then the JVM would require creating an object every time the program starts, leading to unnecessary memory allocation.

Additionally, main() is public to ensure it can be accessed by the JVM from outside the class.


要查看或添加评论,请登录

Ankit Daware的更多文章

  • LIKE Operator in SQL ?

    LIKE Operator in SQL ?

    Like operator is used to compare column values with text patterns. It has 2 wildcard characters % It replaces 0 to any…

  • HOW TO CHANGE DEFAULT DATE FORMAT IN ORACLE SQL DATABASE

    HOW TO CHANGE DEFAULT DATE FORMAT IN ORACLE SQL DATABASE

    Use this query : SYNTAX for Chnaging default date format in SQL : SQL > ALTER Session set nls_date_format = 'dd/mm/yyy'…

  • What Is Database ?

    What Is Database ?

    Database is interrelated data arranged in an organized form. You can understand like complete details about and…

  • What is JIT Compiler in Java ?

    What is JIT Compiler in Java ?

    JIT is Compiler works at runtime for improving program execution. Let's look the complete process of execution of java…

  • What is Encapsulation in Java ?

    What is Encapsulation in Java ?

    Encapsulation is a fundamental concept in object-oriented programming (OOP) , That involves bundling the data (fields)…

  • What is Object in Java ?

    What is Object in Java ?

    In simple words : In Java ,Object is memory created inside "Heap Area" for non-static member of a class. In Addition :…

  • What is Class in Java ?

    What is Class in Java ?

    In Java, Class is a user-defined datatype which represent template or blueprint from which Objects are created. Class…

社区洞察

其他会员也浏览了