What does void do in java?

后端 未结 6 2014
孤城傲影
孤城傲影 2020-11-29 11:52

The return type—the data type of the value returned by the method, or void if the method does not return a value.

http://download.oracle

6条回答
  •  无人及你
    2020-11-29 12:10

    void means it returns nothing. It does not return a string, you write a string to System.out but you're not returning one.

    You must specify what a method returns, even if you're just saying that it returns nothing.

    Technically speaking they could have designed the language such that if you don't write a return type then it's assumed to return nothing, however making you explicitly write out void helps to ensure that the lack of a returned value is intentional and not accidental.

提交回复
热议问题