public static void main(String args[])

In core Java program, execution starts from main method when you type java main-class-name, JVM search for public static void main(String args[]) method in that class and if it doesn't find that method it throws error NoSuchMethodError:main and terminates.

First, why public? 可从任何地方访问此类成员

Propose it is private, then this method can not access outside the class, how jvm excute it?

Because main() method can excute in any java runtime evnironment, JVM need to access and execute it.

Any method or variable which is declared public in Java can be accessible from outside of that class, so declare public.

 

Second, why static? main()方法不应依赖于要创建的任何类的实例

Propose removed static, in order to excute main(), JVM has to create instance of main Class.

but constructor can be overloaded and can have arguments, ther would be no consistent way for JVM to create instance and find main method 

Thrid, why void?  不返回任何值

Main() can be overloaded, from the entry point of  class, it is not supposed to return any value.

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值