+ 1

Why main method is static?

20th Dec 2016, 6:25 PM
Hadjer Hajer
Hadjer Hajer - avatar
4 Respuestas
+ 10
In Java, everything must be written in a class. In order to call a method like main() from a class, you either need to instantiate an object of that class, or it must be made static. Considering main() is the first method that's run, and no objects can be made before then, it must be made static. If you don't understand what that means yet, then don't worry about it.
20th Dec 2016, 7:11 PM
Tamra
Tamra - avatar
+ 5
Not if you're inside the class in question.
20th Dec 2016, 7:39 PM
Tamra
Tamra - avatar
0
but a static method we should call it by the name of the class??
20th Dec 2016, 7:28 PM
Hadjer Hajer
Hadjer Hajer - avatar
0
ok, thank you
20th Dec 2016, 7:40 PM
Hadjer Hajer
Hadjer Hajer - avatar