Static | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Static

Can someone please explain what static means or does in a code such as: public static void main (String[] args)?

13th Jul 2019, 12:07 PM
TheX Gamer
TheX Gamer - avatar
2 Answers
+ 2
static methods and variables do not need their classes to be instantiated, to be able to use them. The main method, which is the entry point of every java program, must always be static. Don't worry about it now, it will be explained later in the java course when you have more idea about the whole object oriented concept... https://www.sololearn.com/learn/Java/2159/
13th Jul 2019, 12:12 PM
Tibor Santa
Tibor Santa - avatar
+ 2
Whenever the compiler or interpreter starts compilation they look for main() method and therefore the main() method should be directly accessible. "static" keyword basically mean that there is no need of object to call a function or method. If you do not use static in your any method then it will need a object to run that method. Compiler while compiling looks for main() method to start the program with and if you do not use static here then main() method will require an object to run which will not be created as compiler picks main() method only in the starting, so basically your program will not run. I know it's a bit clumsy. I hope you get it.
13th Jul 2019, 12:17 PM
Chetali Shah
Chetali Shah - avatar