OU Courese Banner ADBH Web - M206 TMA02 Question 2
ADBH Web 05-Sep-2008

M206 - TMA02 Question 2

(i) Screen capture.

  Screen capture

(ii) The methods which make use of the pseudo-variable self are:- down, height.", hover: by: , initialize, and up. The

pseudo-variable super is only used in the initialize method.

(iii) The protocol of the Frog class is to be extended by the addition of a moveRight:

  • moveRight: aNumber

"Set the receiver to move right by a given number (aNumber) of positions. Answer the receiver."

  • self position:self position + aNumber.

(iv)The protocol of the HoverFrog class is to be extended by the addition of a new message above: for which the method heading and initial comment are as follows.

  • above: aHoverfrog

"Increment the height of the receiver by one or more than the height of HoverFrog (an instance of HoverFrog or its subclasses). Answer the receiver."

  • self height: ((self height) + 1)

(v) What is the message answer obtained from evaluating each of the following expressions?

(a) 3 + (2 * 4) message answer is 11. Smalltalk evaluates the bracketed part of the expression first (brackets take precedence).

(b) 3+ 2 * 4 message answer is 20. Smalltalk in this instance works through the expression from left o right.

(c) 3 plus: 2 * 4 message answer is 20. Smalltalk evaluates the expression to the right of the keyword plus: first then actions the keyword. In effect it is just another way of writing 3 + (2 * 4) as in part (a).

 

Question 1 - Question 3

Top of Page

 

 

 

Page built in 0.0006 seconds