The above examples are pretty much rubbish - but also never ending loops. That can also cause a compiler warning (also error?). You will also get the error due to the return value when you add a
break
condition.
The example
foo4()
is not ever lasting. Therefor it needs to return "something":
public int foo4() {
if(true){ return(5); }
return -1;
}