About Question com.enthuware.ets.scjp.v6.2.720 :
Moderator: admin
About Question com.enthuware.ets.scjp.v6.2.720 :
I have run this program and see that the answer is correct. What stumped me is that there is no return statement and assumed that it will be a compiler error. Can you explain why absence of return statement is being ignored by the compiler?
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.720 :
A method is not required to return a value if it ends abruptly i.e. if it throws an exception. In this case, the compiler notices that the method always throws an exception so it doesn't care for the return statement.
Compilation error occurs when the compiler sees a way or a situation in which the method is not returning a value and is not throwing an exception either.
For example, if you have:
if(someCondition) throw new Exception("oops");
It will realize that if someCondition returns false, the method will not return any value and it is will flag an error.
Compilation error occurs when the compiler sees a way or a situation in which the method is not returning a value and is not throwing an exception either.
For example, if you have:
if(someCondition) throw new Exception("oops");
It will realize that if someCondition returns false, the method will not return any value and it is will flag an error.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 227 guests