Gaurangkumar Khalasi wrote:In your function of "public boolean setFileName()", Compiler can able to see two statements 1) String declaration and 2) If else statements. And as your function has a valid return type other than "void", compiler try to find third statement i.e. return statement. Compiler do not know about your logic of "If-else", it knows about its semantic validation...
So, you got an error...
Gaurang, I will beg to differ here. The compiler knows that if 'if-else' statements are present, then one has to be executed and if each has a return statement then there is no need for the return statement outside if-else block.
In case, where you use only if statement, then you will need that extra return statement outside the if-block because in that case compiler doesn't know whether that if statement will actually be executed.