Question 0-4

Say you want to add a keyword instance method into Smalltalk's built-in Integer class called ``max:'', which returns the maximum value between the Integer instance to which the method is applied and the argument. For example, the code ``3 max: 5'' should return 5, while ``6 max: 2'' would return 6. Write the definition of this method to be added to the Integer class.

Solution

max: other
    self > other ifTrue: [ ^ self ] ifFalse: [ ^ other ]

Back to Exam 0