System.out.println();括號(hào)里面可以直接寫方法名輸出嗎?比如System.out.println(+hello());
豐子凱
2016-08-28 10:37:59
TA貢獻(xiàn)317條經(jīng)驗(yàn) 獲得超240個(gè)贊
可以,但是方法的返回值不能為void
public?class?HelloWorld?{ public?static?void?main(String[]?args)?{ ???????System.out.println(hello()); ???????System.out.println(sayHello());?//會(huì)報(bào)錯(cuò) ????} ???? public?static?void?sayHello()?{ System.out.println("hello"); } public?static?String?hello()?{ return?"hello"; } }
TA貢獻(xiàn)392條經(jīng)驗(yàn) 獲得超170個(gè)贊
可以的System.out.println();是輸出語(yǔ)句,當(dāng)然可以輸出方法,但是方法要有返回值,也就是返回一個(gè)具體實(shí)數(shù),一個(gè)字符,也就是方法返回的不能為空void,
舉報(bào)