You are on page 1of 2

M250 tutorial questions on units 1 & 2

M250 Questions on Units 1 & 2

Quiz Questions
1 What is the relationship between the state of an object and its attributes?
2 The following character has been produced using a word processor: W
When this is considered as a visual representation of a software object, what three of
the following are likely attributes of the object?
(i) font name (ii) printer type (iii) speed
(iv) size in points (v) style (e.g. italic, bold) (vi) document name
3 Are the objects you see in the Two Frogs microworld actual Frog objects? Explain.
4 What is the difference between a variable and an object?
5 What do instances of the same class have in common?
6 Does every message sent to an object change the state of the object?
Explain with examples.
7 In the following statement, identify the receiver, message, message-send, message
name, argument.
kermit.upBy(2);
8 What is meant by saying that HoverFrog objects inherit from Frog objects?
What do they inherit?
9 When, in the course of responding to a message, the receiver object sends another
message to another object, what are the objects said to be doing?
10 Write down the variable(s), class(es), attribute(s) and message name(s) that appear in
the following diagram.

Class of object: Car


kilometresPerLitre 15.4
myCar
topSpeed 130

manufacturer "Ford"

Protocol: (incomplete)
getKilometresPerLitre()
setKilometresPerLitre()
getTopSpeed()
setTopSpeed()
getManufacturer()
setManufacturer()

1
M250 tutorial questions on units 1 & 2

Longer questions
Note that in the longer questions I have sometimes used the informal variable terminology
described on p. 29, by writing, for example "messages sent to hoverFrog1" when what is
meant is "messages sent to the HoverFrog object referenced by hoverFrog1". This is fine so
long as you are clear about what is really meant and do not confuse variables with the
objects that they reference.
11 Write Java statements to perform the following on the instance of Frog referenced by
frog1, and the instance of class HoverFrog referenced by hoverFrog1.
 Set the position of (the Frog object referenced by) frog1 to be its home
position, and set its colour to be its initial colour of Green.
 Set the height of (the HoverFrog object referenced by) hoverFrog1 to be two
below its current height if possible, otherwise leave it unchanged. In which
circumstances will no change be made?
 Set the colour of frog1 to be the same as that of hoverFrog1.
12 Suppose that frog1 references an instance of Frog and hoverFrog1 references an
instance of HoverFrog. The following four statements are each typed into the Code
Pane of the Frog & HoverFrog microworld and then executed.
frog1.setColour(OUColour.RED);
hoverFrog1.right();
hoverFrog1.upBy(1);
hoverFrog1.sameColourAs(frog1);
(i) Write down the messages in these lines that have arguments.
(ii) Write down the messages in these lines that don't have arguments.
(iii) How many messages are sent to hoverFrog1 as a result of the evaluation of
these four lines? What is the message name in each case?
(iv) In the third line, identify the receiver, the message, the message name and the
arguments.
13 (i) Suppose that the state of Account object (referenced by) ac123 has balance set
to 77.0, and that ac456 references another Account object. Draw a sequence
diagram to show the sequence of messages that are sent as a result of sending
to ac123 the message transfer(ac456, 50). What is the message answer?
(ii) After this the same message is sent once more to ac123. Draw a sequence
diagram for this interaction. What is the message answer in this case?

You might also like