+ 2

In which reason I should add static keyword to a method?

29th Dec 2019, 2:32 PM
Hichem GOUIA
Hichem GOUIA - avatar
2 Answers
+ 3
Generally if you are declaring a method inside the class which has your main() then it is recommended to use static keyword for the method which is going to be accessed within the main(). Because main() itself is static and you cannot access a non-static member inside a static method until and unless you create an Object of that class.
29th Dec 2019, 2:37 PM
Avinesh - avatar
+ 5
Main reason of using static keyword is accessing methods or variable without insatnce of class.
29th Dec 2019, 4:03 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar