Java error missing return statement are those error in Java that occurred when a programmer forget to write a return statement inside the conditional clauses. method with a non-void return provides you an object of the specific type.
In this Example we want to describe you a code that explain you in understanding Java error missing return object. For this we have taken a non void method 'operation( )'that return you an int type and this method include a for loop clause that check the condition If there is anything other than void method, then you must specify the return type in it. The given below code is missing a return statement in the non-void method so, whenever the compiler execute the code the code returns a missing return statement error.
There are two way to resolve this problem-
1)Change the non-void method to a void method.
2)Add or write a return expression to the non-void method.
Missingreturnstatement.java
|
public class Missingreturnstatement { public int operation(int num) { for (int i = 0; i <= num; i++) { System.out.println(i); } } public static void main(String[] args) { Missingreturnstatement m = new Missingreturnstatement(); m.operation(7); } } |
|
Compiling 1 source file to /home/girish/NetBeansProjects/errors/build/classes /home/girish/NetBeansProjects/errors/src/ Missingreturnstatement.java:9: missing return statement
} |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java error missing return statement
Post your Comment