Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1373 :

Posted: Thu Nov 14, 2013 12:33 pm
by Zoryanat
Hi there.

I was under impression that we look at reference class to see what methods we have access to but if the method in question is overridden in subclass, and actual object that reference referring to is of that subclass, then the overridden version of that method will be called.
Here though you say "2. Whether a call needs to be wrapped in a try/catch or whether the enclosing method requires a throws clause depends on the class of the reference and not the class of the actual object." - is that something that applies only in cases when throwing exceptions is involved?

Re: About Question enthuware.ocajp.i.v7.2.1373 :

Posted: Thu Nov 14, 2013 1:06 pm
by admin
Hi there.

I was under impression that we look at reference class to see what methods we have access to but if the method in question is overridden in subclass, and actual object that reference referring to is of that subclass, then the overridden version of that method will be called.
That is correct.
Here though you say "2. Whether a call needs to be wrapped in a try/catch or whether the enclosing method requires a throws clause depends on the class of the reference and not the class of the actual object." - is that something that applies only in cases when throwing exceptions is involved?
I am not sure I understand your question but this goes back to your point 1 above. You are looking at the declaration of the method in the class of the reference (not of actual object) to determine whether you have to put the call in try/catch or not (Or declare the throws clause of the caller appropriately).

HTH,
Paul.