gpt4 book ai didi

java - 'String args[]'和 'public static void main(String[] args)'中的static的解释

转载 作者:行者123 更新时间:2023-12-01 21:39:21 25 4
gpt4 key购买 nike

您如何向初学者很好地解释 String args[] 的含义?以及 static 的使用在下面的摘录中?

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

最佳答案

我会分手

public static void main(String args[])

部分:

public

It means that you can call this method from outside of the class you are currently in. This is necessary because this method is being called by the Java runtime system which is not located in your current class.

<小时/>

static

When the JVM makes call to the main method there is no object existing for the class being called therefore it has to have static method to allow invocation from class.

<小时/>

void

Java is platform independent language and if it will return some value then the value may mean different things to different platforms. Also there are other ways to exit the program on a multithreaded system. Detailed explaination.

<小时/>

main

It's just the name of method. This name is fixed and as it's called by the JVM as entry point for an application.

<小时/>

String args[]

These are the arguments of type String that your Java application accepts when you run it.

关于java - 'String args[]'和 'public static void main(String[] args)'中的static的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58796349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com