Static Keyword
What is use of Static keyword under Main method
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bhuvanesh MohankumarPosted May 4, 2016, 5:56 AM
Accept as answer, if it was helpful.
Munesh SharmaPosted May 1, 2016, 11:51 AM
You need an entry point into your program. Static means that you can call the function without having to instantiate an object/instance of a class. Its a bit "chicken and egg"... you can't instantiate an object before you're inside the program.
A static method can be called without instantiating an object. Therefore main() needs to be static in order to allow it to be the entry to your program.
As David says you can just add the keyword
staticto the function definition to change it. Its worth looking into static (class) methods vs instance methods, and knowing the difference can be useful at times.Vivek KumarPosted Apr 29, 2016, 12:27 PM
Amit Kumar SinghPosted Apr 29, 2016, 5:50 AM
You need an entry point into your program. Static means that you can call the function without having to instantiate an object/instance of a class. Its a bit "chicken and egg"... you can't instantiate an object before you're inside the program.
A static method can be called without instantiating an object. Therefore main() needs to be static in order to allow it to be the entry to your program.
the keywordstaticto the function definition to change it. Its worth looking into static (class) methods vs instance methods, and knowing the difference can be useful at times.