+ 3

Is void method with or without a parameter can return an int value?

5th Aug 2017, 1:45 AM
PandaPandađŸŒ
PandaPandađŸŒ - avatar
2 Answers
+ 13
@Renzo : No, it's not so. You can create objects to call a void method as well as an int method, etc... It's just that if you want to return an int value, you should define a method of the int type. This is clearly covered in the Java course!
5th Aug 2017, 2:09 AM
Dev
Dev - avatar
+ 14
Any method declared `void` doesn't return a value. It does not need to contain a return statement. If you try to return a value from a method that is declared void, you will get a compiler error.
5th Aug 2017, 1:50 AM
Dev
Dev - avatar