zoukankan      html  css  js  c++  java
  • java学习基础

    Q: What if the static modifier is removed from the signature of the main method?

    A: Program compiles. But at run time throws an error "NoSuchMethodError".

    1、public:java类是由JVM调用的,显而易见为了让JVM可以自由的调用main方法,所以使用public修饰符把这个方法暴露出来。

    2、static:说明main方法是静态方法,如果将static去掉,编译程序不会出错,但是运行时就会出现报错:找不到main函数。因为包含main函数

    的类没有实例化,所以main方法不会存在。因为方法和属性都是建立在对象之上的,没有对象其他的也都没有。

    3、void:因为main函数是被JVM调用的,该方法的返回值将返回给JVM,这没有任何意义。

    4、String[] args 形参:参数的类型是String[] (重点)

    注意:static方法不能调用非static方法,把main()方法定义成静态的,就是解决既能直接调用静态方法又能间接调用非静态方法(比如:类名.非静态方法)。
  • 相关阅读:
    上传文件事件并校验:event.target.files && event.target.files[0]
    深浅拷贝
    Git学习
    Flex弹性布局
    hive
    222
    错误总结
    Redis小结2
    spark小结
    kafka详解
  • 原文地址:https://www.cnblogs.com/Code-Engineering/p/5745415.html
Copyright © 2011-2022 走看看