+ 3

why the main method in Java is always static ?

8th Sep 2016, 4:41 PM
Sambit Mohapatra
Sambit Mohapatra - avatar
5 Antworten
+ 6
This is necessary because main() is called by the JVM before any object is made.since it is static it can be directly invoked via the class.
8th Sep 2016, 5:42 PM
Rahul
Rahul  - avatar
+ 4
because we don't need to create an instance from it
3rd Feb 2017, 10:21 PM
L Boudhar
L Boudhar - avatar
+ 3
because for a static method there is no need to create an object
11th Sep 2016, 5:21 PM
Dheeraj Reddy
Dheeraj Reddy - avatar
+ 1
1. by rule of Java, you should write the same syntax defined for main(). 2. static members are loaded first during the execution, so main has to be static as the execution starts from there only. 3. if it is not declared as static compiler throws error, cz its not according to the syntax. Also, you can see that we never create any instance for the main function, since it has to be static.
19th Sep 2016, 1:53 PM
Tanya
Tanya - avatar
+ 1
Suppose if we do not make main method static then we have to create the object of main method. but the question arises is where we create the object of main method. That's why we make the main method static so that it can be accessed by the class name and we don't need to create the object of main method.
3rd Feb 2017, 4:37 PM
Ashu Bagul
Ashu Bagul - avatar