Page 1 of 1

About Question enthuware.ocpjp.v7.2.1102 :

Posted: Wed Jun 11, 2014 9:18 am
by kashyapa
   static int oops(int i) throws Exception    {
      throw new Exception("oops");    
}
There's no return statement.
so i selected "it will not compile" :evil:

Re: About Question enthuware.ocpjp.v7.2.1102 :

Posted: Thu Jun 12, 2014 12:06 am
by admin
Yes, that's makes it interesting :)

-Paul.

Re: About Question enthuware.ocpjp.v7.2.1102 :

Posted: Sun Dec 21, 2014 8:44 pm
by leorbarbosa
Very interesting, but technically I couldn't understand. The compiler simply ignores the required return type.

Re: About Question enthuware.ocpjp.v7.2.1102 :

Posted: Sun Dec 21, 2014 10:02 pm
by admin
No, the compiler doesn't ignore the return type. Any method is allowed to either return a value (that is of the same type as the return type defined for the method) or throw an exception. The fact that a method always throws an exception (as is the case here) doesn't change anything.