CS 535 Object-Oriented Programming and Design

Fall Semester, 2008

Sample Questions

Course Web Site

© 2008, All Rights Reserved, SDSU & Roger Whitney

 San Diego State University -- This page last updated 10/15/08

Here are some questions that have appeared on past CS 535 exams. They may or may not be related to questions on future exams.  

1. Describe the Smalltalk naming convention for:

a. Classes

b. Instance variables

c. Arguments to a method

2. What is the difference between True and true in Smalltalk?

3. Explain the difference between self and super. Give an example as part of your explanation. If you define classes for you example give the parent class, class name, instance variables and methods. The exact template for creating a class is not needed.

4a What is an overridden method. Given an example.

4b What are the Smalltalk rules for overriding instance variables?

5. Let aCollection contain a collection of numbers. Use inject:into: to find the smallest element in aCollection.

6. Explain the difference between OrderedCollection and a Bag.

7. What is polymorphism? Give an example.

8. Write a Smalltalk program to print the odd numbers between 21 and 5342 on the Transcript.

9. What is the difference between == (double equals) and = (single equals) in Smalltalk?

10. What is the difference between select: and collect:?

11. What is a Template method? Give an example of the use of Template Method in the Smalltalk class library.

12. Given the methods below what is printed on the Transcript by executing the expression: ‘ Exam new a’



      show: 'Start a’;


   self b.


      show: 'End a’;





      show: 'Start b’;


   self c: [^5].


      show: 'End b’;


Exam>>c: aBlock


      show: 'Start c’;


   aBlock value.


      show: 'End c’;


13. Given the classes and methods below what is the result of executing each of the following expressions individually with “print it”?

C new foo

C new bar

A new foo

Class         A

Superclass         Object





Class         B

Superclass A





        ^self x


        ^super x

Class         C

Superclass         B




14. Parenthesis the following expressions to indicate the order that messages will be sent in the expression. For keyword messages list separately the full keyword message name.

a.         y asSet asBag printString.

b.         1 * 2 + 3 - 4 / 5 * 6 - 1.

c.         circle origin = 1 @ 2.

d.         sam long age: x x + x x.

e.         cat printString copyFrom: dog size to: mouse at: 2.

f.         Circle new  origin: 3 @ 2; radius: cat at: 2; color: dog displayColor.

15. Write a class method for a class named Foo that has one argument that is an ordered collection of strings. Return the list sorted by the second character.

16. Write SUnit test method(s) for the sort method in the above problem.