0 votes
1 view
in Java by (2.4k points)

1 Answer

0 votes
by (5.4k points)
The simple answer is" "Static functions don't require objects to run while non-static functions do."

The main function is the driver code of any program. If the main function is absent, we can only compile the code but can't execute it. The JAVA virtual machine needs to know what it has to execute and it cannot start executing a random program module unless it is commanded to. The main functions do exactly that and the execution of any program in JAVA does not occur without the driver code. If we make the main function non-static, JVM would have to create an object of the class the main function resides in to run the driver code as it stands and this will cause unnecessary and extra memory allocation.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...