Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Can a void method have a return statement?

0
Posted

Can a void method have a return statement?

0

Though void means that it does not return a value…. if we are defining our function as void that means we dont want it to return values to us. But in some cases, we can have an if loop inside the function which checks whether it is valid to continue or not, in that case if it is invalid then we can write the statement return without any values… this will make the function go to the end of the method and return as a failure. As it is not returning any value we do not need to write the function as an int. public void check() { if(argv < 2) { return; } ..... normal functioning ..... .. } this checks for the command line argument, if the no of arguments are less than 2, there can not be any functioning, in this case program needs to be terminated....

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123