gpt4 book ai didi

java - 创建不带参数的方法和创建字符串参数的方法之间的区别?

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

我只是想知道创建一个不带参数的方法与创建一个带字符串参数的方法有什么区别。据我了解,没有定义参数的方法可以在程序中的任何位置调用,而带有字符串参数的方法仅适用于字符串(不确定)?例如

public static void exampleOne(){
}

对比

public static void exampleOne(String x){
}

最佳答案

如果您向这些方法添加一些代码,术语将清晰地弹出 =)

public static void exampleOne(){
System.out.println("hello World");
}

public static void exampleTwo(String x){
System.out.println("hello World, "+x);
}

然后您可以通过提供字符串 x 对 exampleTwo 的结果进行参数化

exampleOne(); //will print Hello World

exampleTwo("BipoN"); //will print Hello World BipoN

关于java - 创建不带参数的方法和创建字符串参数的方法之间的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58849585/

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