Homework: Review III
Here are some review questions to give you extra practice with
what you have learned so far and help you prepare for the second
midterm exam.
- Implement the following two static methods. Note that,
although the two methods compute the same function, the first one
clears the given NaturalNumber while the second
one restores it.
- Implement the static method declared as follows:
- Implement the static method declared as follows:
- For each of the following terms (in no particular order),
provide a short definition.
- design-by-contract
- precondition
- postcondition
- testing
- debugging
- parameter mode
- clears
- replaces
- restores
- updates
- immutable type
- primitive type
- reference type
- object
- aliasing
- declared type/static type
- object type/dynamic type
- implements
- extends
- method overriding
- subinterface/derived interface/child interface
- superclass/base class/parent class
- polymorphism
- recursion
- Carefully trace over the following code. Draw a picture (of
the kind used in Arrays
and References, slide #5) of the value of the array after the
initialization code completes.
What is wrong with the code above and how would you fix it so that
its behavior matches the comment?
- Argue from the definition of extends that NaturalNumber
extends Standard as shown on slide 2 of Concepts
of Object-Oriented Programming.
- Argue from the definitions of extends and implements
that C4 implements I2 and that C3
implements I1 on slides 11-12 of Concepts
of Object-Oriented Programming.
Additional Questions
- Implement the static method declared as follows:
- Modify your implementation of the static method toInt
so that it is an instance method for NaturalNumber
declared as follows: