About Question enthuware.ocpjp.v7.2.1102 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
kashyapa
Posts: 23
Joined: Thu May 08, 2014 5:27 am
Contact:

About Question enthuware.ocpjp.v7.2.1102 :

Post 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:

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

Yes, that's makes it interesting :)

-Paul.

leorbarbosa
Posts: 17
Joined: Wed Nov 26, 2014 1:59 pm
Contact:

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

Post by leorbarbosa »

Very interesting, but technically I couldn't understand. The compiler simply ignores the required return type.

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests