Deepakk Verma wrote:if we have a method with return type boolean then is it compulsory to have both true and false returns . . .
To answer the question you asked, rather than the question you thought you asked:
No.
You can have a method which always returns true or false. It is a bit useless, but is legal syntax.
The reason you had problems with your first example which didn't compile is that there were circumstances where the method returned nothing at all. If you give "foo" as the return type, the method must return a "foo" from every path.