CS 535 Object-Oriented Programming
Fall Semester, 2003
© 2003, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 15-Sep-03
Remove the parentheses in the following expressions that are not needed. That
is remove all parentheses you can without changing the result of the expression.
(3+5) raisedTo: ((3 squared) + 7)
(5 factorial) between: (3 squared) and: (3 * 5 * 9)
Assume we have the following class definitions and methods:
the following assignments
exampleC := C new.
exampleD := D new.
what happens with each of the following expressions:
What protocol of the Number class contains the method raisedTo:
Which subclasses of Number implement raisedTo:?
Why does Number implement raisedTo: when subclasses override the method?
Create a method in the Number class called tax that returns the amount of sales
tax on the receiver. Use 0.0725 has the sales tax rate. Use the following code
to test your method. (For this problem just turn in your source code for the
| price |
price := (Dialog request: 'Please enter price' initialAnswer: '100') asNumber.
show: 'price: ', price printString; cr;
show: 'tax: ', price tax printString; cr
To see how scoping of different variables works, create a new class called
give it as many different variables of the same name as possible. (E.g., an
instance variable named “
a shared variable named “
Also, add a method of the same name as instance variable. Besides answering the questions below turn
in your source code for the class.
How many different variables with the same name can you access in one method?
Can you access an instance variable and a local variable with the same name in
one method? Explain what happens when you try this.
visitors since 08-Sep-03