Saturday, 17 December 2016

Not all code paths return a value

If you return any thing from method instead of void then you must return the defined type value as described in return type.Case 1. If you are using for , while loop or any other conditional statement then you should use return statement in all places like below.

publicstaticbool isTwenty(int num)

{

for (int j = 1; j <= 20; j++)

{

if (num % j != 0)

{

returnfalse;

}

elseif (num % j == 0 && num == 20)

{

returntrue;

}

}

returnfalse;

}

Case 2. If you are using Try Catch then Give return or throw in both try and catch Or give in finally only as below.