Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does the return in main() return to? [duplicate]

Tags:

java

return

Possible Duplicate:
Who calls the main function in java?

Consider this code:

class abc {
  public static void main(String x[]) {
    return;
  }
}

Where does control go to when return is reached? When we execute this program, say via

$ java abc

the compiler searches for the main method and then proceeds further. In other cases, we call a function, and if we reach a return, control is returned to the last calling point.

like image 697
nr5 Avatar asked Dec 31 '25 01:12

nr5


1 Answers

The control is always returned to the call originator. In this case, the originator could be the operating environment, or another method that called main (remember, when it comes to being called, main is not special in any way; other methods can call it too).

like image 74
Sergey Kalinichenko Avatar answered Jan 02 '26 13:01

Sergey Kalinichenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!