Void and return in Java - when to use

后端 未结 7 1937
予麋鹿
予麋鹿 2020-12-18 17:10

I have some \"confusion\" about void and return. In general, I understand void is used in methods without returning anything, and return is used in methods when I want to re

7条回答
  •  难免孤独
    2020-12-18 17:58

    return should not be used with void class type as the program output is returned by default and can be displayed through appropriate methods of the java class, like when you want to display the output of your program:

    System.out.println("number = " + number);

提交回复
热议问题