Using static keyword with main() | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Using static keyword with main()

Why do we use static keyword with the main() function, please, describe in brief?

15th Sep 2019, 4:40 AM
preetpal singh
4 Respostas
+ 3
Somewhere I have read this explanation: A static method belongs to the class and not only to the instance. If the main method would be non static you would need to create an instance. But to create an instance you need the main method which executes your code.
15th Sep 2019, 8:10 PM
Denise RoƟberg
Denise RoƟberg - avatar
+ 1
But we describe the statements in the main method, why would someone want to write a constructor for the main?
15th Sep 2019, 5:53 PM
preetpal singh
+ 1
Yes, you are right there are too many doubts about the main() method itself. Anyway, thanks for your assistance.
15th Sep 2019, 6:08 PM
preetpal singh
+ 1
Ok, if we are gonna call the main function using classname.main()(as it is static) in other class, what will happen then?
16th Sep 2019, 2:23 AM
preetpal singh