Page 821 - AP Computer Science A, 7th edition
P. 821

20. (D) A new Temperature object must be constructed to prevent the current Temperature from being changed. Segment I, which applies the conversion formula directly to degrees, is the best way to do this. Segment II, while not the best algorithm, does work. The statement
result = result.raise(32);
has the effect of raising the result temperature by 32 degrees, and completing the conversion. Segment III fails because
degrees ∗ = 1.8;
alters the degrees instance variable of the current object, as
does
this = this.raise(32);
To be correct, these operations must be applied to the result object.



























































































   819   820   821   822   823