Why main method is static

Why main method is static

Answer: The main() method in C++, C# and Java are static because they can then be invoked by the run time engine without having to instantiate an instance of the parent class.This is how Java Language is designed and Java Virtual Machine is designed and written.

See below what Oracle Java Language Specification says:

After completion of the initialization for example class Test (during which other consequential loading, linking, and initializing may have occurred), the method main of Test is invoked.
The method main must be declared public, static, and void. It must accept a single argument that is an array of strings. This method can be declared as either

public static void main(String[] args)
or
public static void main(String… args) 

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *