3 回答
已采纳

yanrun
TA贡献317条经验 获得超240个赞
可以,但是方法的返回值不能为void
public class HelloWorld { public static void main(String[] args) { System.out.println(hello()); System.out.println(sayHello()); //会报错 } public static void sayHello() { System.out.println("hello"); } public static String hello() { return "hello"; } }

噼喱啪啦
TA贡献392条经验 获得超170个赞
可以的System.out.println();是输出语句,当然可以输出方法,但是方法要有返回值,也就是返回一个具体实数,一个字符,也就是方法返回的不能为空void,
添加回答
举报
0/150
提交
取消