0

Why we will not write return in void main ??

26th Aug 2016, 2:28 AM
suji prem
suji prem - avatar
2 Answers
+ 1
As a matter of fact we could use return with void methods, but with no returned value See ex: in below public class Program { public static void main(String[] args) { showPositive(9);// prints 9 showPositive(-5);// prints nothing } public static void showPositive(int i){ if(i<0) { return; } System.out.println("i=" + i); } }
26th Aug 2016, 3:38 AM
Tiger
Tiger - avatar
0
Because main returns no value. Where would you want to return a value to?
26th Aug 2016, 6:36 AM
Frostbyte