How do I declare a static variable inside the Main method?

后端 未结 6 1939
予麋鹿
予麋鹿 2020-12-03 22:42

Can we declare Static Variables inside Main method? Because I am getting an error message:

Illegal Start of Expression
6条回答
  •  借酒劲吻你
    2020-12-03 23:43

    Obviously, no, we can't.

    In Java, static means that it's a variable/method of a class, it belongs to the whole class but not to one of its certain objects.

    This means that static keyword can be used only in a 'class scope' i.e. it doesn't have any sense inside methods.

提交回复
热议问题