I am a beginner in java and am writing a stack class using array.
So I have a method in this class called pop
public int Pop(){
if (current_size >0)
{ // do something
return ele;
}
// return nothing <-- ths is where error is
}
Since i have the return type int.. the class is always expecting to return something.
How should I tackle such cases where the method wil return something if the condition is true else it wont shouldnt return anything?
Thanks
You must always return something (unless your method is
void) or throw an exception. You could try this: