0

Why is the main method declared as "static" in java?

10th Nov 2016, 4:05 PM
nitin sachdev
nitin sachdev - avatar
2 odpowiedzi
+ 2
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.
10th Nov 2016, 7:03 PM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
+ 1
When you use static keyword for function and variables. You don't need to create object to access variable or function. like class_name.function_name
10th Nov 2016, 5:07 PM
Aditya kumar pandey
Aditya kumar pandey - avatar