27

java基础(二)--main方法讲解

 3 years ago
source link: http://www.cnblogs.com/mrwhite2020/p/13379680.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

main()函数是如下的固定格式,除了args可以修改名字,其余均不可以修改

public class TestBase02MainMath {
    public static void main(String[] args) {
    }
}

一、public

表示程序的访问权限,表示的是任何的场合可以被引用。

二、 static

“static”表示方法是静态的,不依赖类的对象的。

三、 void

表示main()方法是不需要返回值的。

四、main()

每个项目都需要要有一个main函数,怎么程序找不到主入口.

main()是java程序的入口地址,java虚拟机运行程序的时候首先找的就是main方法

五、 String[] args

参数String[] args是一个字符串数组,接收来自程序执行时传进来的参数。

六、大括号{}

所有的语句写在其中。

一般情况下,变量的作用域为:出了{}就不认识了。

一个{}代表一个域,同一个域内,变量不能重复赋值


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK