Return Statement in Java

While discussing about methods we have already encountered return statement. This statement is used to manually return a control from a method to the actual workflow. In a method, whenever the workflow meets a return statement, it returns the workflow from there without executing any more statements in that method.


public class ReturnDemo {
	public static void main(String[] args) {
	public static int returnValue()
		int i = 0;
		return i;		
Try It

Unreachable Code Error

Any statement written after the return statement will give you an error while compiling. This is because compiler is telling you that you have written return from where your workflow will break and the code after return is not accessible and unreachable.

Next > < Prev
Scroll to Top