Java程序中可以存在两个主要方法吗? [英] Can there exist two main methods in a Java program?

查看:31
本文介绍了Java程序中可以存在两个主要方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 程序中可以存在两个主要方法吗?

Can two main methods exist in a Java program?

仅在于他们的论点不同,例如:

Only by the difference in their arguments like:

public static void main(String[] args)

第二个可以

public static void main(StringSecond[] args)

如果可能,将使用哪个 Method 作为入口点?如何识别?

If it is possible, which Method will be used as the entry point? How to identify this?

推荐答案

只要方法参数(数字(或)类型)不同,就可以.它被称为重载.

As long as method parameters (number (or) type) are different, yes they can. It is called overloading.

重载方法通过传递给方法的参数的数量和类型来区分

Overloaded methods are differentiated by the number and the type of the arguments passed into the method

public static void main(String[] args)

只有以单个 String[](或)String... 作为参数的 main 方法才会被视为程序的入口点.

only main method with single String[] (or) String... as param will be considered as entry point for the program.

这篇关于Java程序中可以存在两个主要方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆