why we declare main () method as static? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

why we declare main () method as static?

why we do not create instances of static method?

6th Sep 2016, 4:50 PM
Amit Kakade
Amit Kakade - avatar
7 ответов
+ 3
This topic is beyond explaination within here however you might want to browse or check oracle, tutorialspoint or stackoverflow. However in simple terms, the main method is static because this allows us to use it without needing to make an instance in order to access it.
6th Sep 2016, 5:07 PM
Ousmane Diaw
+ 1
static method called without object creation so at the first time running of code main is called so it is declared as static
7th Sep 2016, 5:15 PM
Dinesh Kumar
Dinesh Kumar - avatar
0
technically main is declared as static because in the beginning of executions the os hand over the control to the JVM and then JVM give the control to class loader and class loader scan the code for static hence we declare main as static .....static is first thing which executed first.....hope u understand... happy coding
7th Sep 2016, 9:24 AM
Abhishek Kumar
Abhishek Kumar - avatar
0
what is class loader?
7th Sep 2016, 1:55 PM
Amit Kakade
Amit Kakade - avatar
0
class loader is a part of Jre .... which dynamically load java classes into jvm
7th Sep 2016, 2:44 PM
Abhishek Kumar
Abhishek Kumar - avatar
0
why class loader scan code for static only?
7th Sep 2016, 4:21 PM
Amit Kakade
Amit Kakade - avatar
0
if I declare any static method then how to call it without creating object?
7th Sep 2016, 5:37 PM
Amit Kakade
Amit Kakade - avatar