zoukankan      html  css  js  c++  java
  • 5、main方法详解

    public class HelloWorld {
        public static void main(String[] args){
            System.out.print("Hello World!");
        }
    }

    在Java中,main()方法是Java应用程序的入口方法,也就是说,程序在运行的时候,第一个执行的方法就是main()方法,这个方法和其他的方法有很大的不同,比如方法的名字必须是main,方法必须是public static void 类型的,方法必须接收一个字符串数组的参数等等。

    另一个版本的Hello World

    public class HelloWorld2 { 
        static { 
            System.out.println("Hello Wordld!"); 
        } 
        public static void main(String args[]){ 
            System.exit(0); 
        } 
    }

    这个main()方法执行的内容就一句"System.exit(0);" ,目的是让程序正常结束。那“HelloWorld!”是从哪里打印的,秘密就是在static打印的,因为static代码块的内容会在main调用前调用。

  • 相关阅读:
    The nineteenth day
    The eighteen day
    弱读下
    弱读上
    失爆 爆破音
    连读
    The seventeenth day
    The sixteenth day
    React 官方脚手架 create-react-app快速生成新项目
    pc端引入微信公众号文章
  • 原文地址:https://www.cnblogs.com/caoyc/p/4341841.html
Copyright © 2011-2022 走看看