public static void main(String[] args) 分析

来源:互联网 发布:数控铣床编程教学 编辑:程序博客网 时间:2024/05/01 20:57

public static void main(String[] args)

  (1)public:表示main方法可以由任何对象调用。(java虚拟机调用main方法所以必须为public)
  (2)static:表示这是一个类方法,区别于实例方法,与具体的对象无关。
  (3)void:表示main方法没有返回值。
    (4)String []args 是声明args可存储字符串数组;他是用来接受命令行传入的参数且只能为字符串
  
   (1)public: It must be declared public.
  (2)static: It must be declared static because it is being called on the class, not on a specific instance.
  (3)void: Its return type is void because it doesn't return a value.
  (4)String []args: Its only parameter is a String array that holds optional arguments passed to the class on the java command line.

  main方法是Java语言中非常特殊的方法,类似于C/C++中的main函数。当Java解析器执行Java应用程序,它首先执行这个Java类的main方法。

原创粉丝点击