Previous | Home | Next |
Return is also a keyword which is used to transfer the control from called method to calling method with or without some value. The return statement immediately terminates the method in which it is executed.
Example :
class Return { static int sum(int a, int b) { int c; c=a+b; return(c); } public static void main(String args[]) { int ans=sum(5,6); System.out.print(ans); } }
output :
11
It is not a keyword it is a static method of class system it is used to terminate entire program. 0 for success or 1 for failure.
- Description:The java.lang.System.exit() method terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.
- Declaration:
- Parameters:status -- This is the exit status.
- Return Valu:This method does not return any value.
public static void exit(int status)
Example :
class Exit { public static void main(String args[]) { for(int i=1;i<=5;i++) { if(i==3) { System.exit(0); System.out.print(i); } } System.out.print("Matrix"); } }
Previous | Home | Next |