How does the main method work?

后端 未结 6 1653
一整个雨季
一整个雨季 2020-12-11 08:27

I\'m the product of some broken teaching and I need some help. I know that there is this thing called the \"main method\" in Java and I\'m sure other programming languages.

6条回答
  •  悲哀的现实
    2020-12-11 09:06

    Breaking this down, point-by-point, for the general case:

    1. All Java applications begin processing with a main() method;
    2. Each statement in the main executes in order until the end of main is reached -- this is when your program terminates;
    3. What does static mean? static means that you don't have to instantiate a class to call the method;
    4. String[] args is an array of String objects. If you were to run your program on the command line, you could pass in parameters as arguments. These parameters can then be accessed as you would access elements in an array: args[0]...args[n];
    5. public means that the method can be called by any object.

提交回复
热议问题