What does void do in java?

后端 未结 6 2016
孤城傲影
孤城傲影 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:11

    The reason the code will not work without void is because the System.out.println(String string) method returns nothing and just prints the supplied arguments to the standard out terminal, which is the computer monitor in most cases. When a method returns "nothing" you have to specify that by putting the void keyword in its signature.

    You can see the documentation of the System.out.println here:

    http://download.oracle.com/javase/6/docs/api/java/io/PrintStream.html#println%28java.lang.String%29

    To press the issue further, println is a classic example of a method which is performing computation as a "side effect."

提交回复
热议问题