When I was reading book about Java , I saw one example written like this. And I am wondering can I declare variable in outside of main method ? What is difference between declar
There is a scope difference. And you have to declare it as static because your main function is static so it allows you to use only static variables. Variable which declares inside main method would only be used inside main method only.
Now you might wondering that why I need to have main method as static!!! As any application in java will run from main method so it can be called by class name only without creating any object so we are defining it as static. All static method can call with class reference, no object needed.